重定向是正确的解决方案。
我能够使用 url 映射使其工作。到目前为止它有效:-)
我从这样的事情开始:
"/**" (controller: 'app', action: 'index')
app/index 是 Angular 应用页面。但这也将匹配其他所有内容(例如 /$controller/$action)。我必须将每个 $controller/$action 显式映射到正确的控制器。不太好... ;-)
为了解决这个问题,我在所有 uris 前面加上/client
angular route 和/server
grails uris。这使得 url 映射变得容易,它有助于区分角度路由和模板 uris 等。
我的最终 url 映射如下所示:
class UrlMappings {
static excludes = [
"/lib/**",
"/css/**",
"/js/**"
]
static mappings = {
// - all client uris (routes) will start with '/client/',
// - all server uris (load) will start with '/server/'
// redirect /$appName/ to /$appName/client
"/" (controller: 'redirect', action: 'redirectTo') {
to = '/client/'
permanent = true
}
// redirect any angular route
"/client/**" (controller: 'app', action: 'index')
// standard controller/action mapping
"/server/$controller/$action/$id?" {
constraints {
}
}
}
}
不能直接在 url 映射中重定向,所以我使用一个简单的控制器:
class RedirectController {
def redirectTo () {
redirect (uri: params.to, permanent: params.permanent)
}
}
路由条目如下所示:
$routeProvider.when ('/client/login', {templateUrl: './server/security/login'});