[英]Using a function in the router's “redirectTo” to determine where to redirect prevents aot
我正在使用一个函数来确定在加载网站时应将用户重定向到何处。 像这样:
{ path : '', redirectTo: redirector(), pathMatch: 'full' }
redirector()
返回一个路由(字符串),例如: 'home/browse'
这会导致ng build --prod --aot
以下问题
Uncaught Error: Invalid configuration of route ''. One of the
following must be provided: component, redirectTo, children or
loadChildren
在这里,您可以看到一个github问题,该问题也与角度防护(条件)重定向有关。
github问题的示例解决方案是(在前面的评论中, @ David Alsh也提到过):
{path: '', pathMatch: 'full', children: [], canActivate: [RedirectGuard]}
然后在RedirectGuard
的canActivate
方法可以使用: this.router.navigate()
其中this.router
是Router
从'@angular/router'
: https://angular.io/guide/router ,为了执行重定向。
使用this.router.navigate()
示例 :
this.router.navigate(['/heroes']);
您可以在此stackoverflow问题中找到更多详细信息。
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.