我有一个奇怪的问题.我有一个像这样的基本路由配置:
const appRoutes: Routes = [
{path: '', redirectTo: '/search', pathMatch: 'full'},
{path: 'login', component: LoginComponent },
{path: 'dashboard', component: DashboardComponent, canActivate: [OnlyLoggedInGuard]},
{path: 'search', component: SearchComponent, canActivate: [OnlyLoggedInGuard]}
];
Run Code Online (Sandbox Code Playgroud)
在应用HTML上,我有条件地导入路由器插座:
<div *nfIf="condition">
...
<router-outlet></router-outlet>
...
</div>
<div *nfIf="!condition">
... another dom construction
<router-outlet></router-outlet>
...
</div>
Run Code Online (Sandbox Code Playgroud)
我拦截(带有HttpInterceptor)HTTP 401错误以重定向到登录页面.在我的http拦截器中的某些意义上我有这样的意思:
this._router.navigate(['/login', {error:'I am an error message'}]);
Run Code Online (Sandbox Code Playgroud)
当我在仪表板上并且发生401时,我正确地重定向到具有正确错误参数的登录页面.但是,当我在登录页面上并从服务器获得401时,我遇到以下错误:
core.es5.js:1020 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'component' of null
TypeError: Cannot read property 'component' of null
at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseRoutes (router.es5.js:4343) …Run Code Online (Sandbox Code Playgroud)