角度版本:4
从登录后LoginComponent
(位于public/signin
路线,我想导航到TestComponent
在路径中public/test
。
我这样做如下:this._router.navigate(['public/test'])
然后,它正确重定向,但问题是它没有删除LoginComponent
来自 DOM(尽管ngOnDestroy
确实被呼叫)。
值得一提的是,导航到TestComonent
using
<a routerLink='/public/test'>Test</a>
按预期工作。
我究竟做错了什么?
应用程序.路由.ts:
const APP_ROUTES:Routes = [
{path: 'public', loadChildren: './authentication/authentication.module#AuthenticationModule'}
];
export const APP_ROUTING:ModuleWithProviders = RouterModule.forRoot(
APP_ROUTES, {
useHash: false, enableTracing: true, initialNavigation: true});
`
authentication.routing.ts(这两个组件都属于其中):
const routes: Routes = [
{
path: '',
children: [
{path: 'test', component: TestComponent},
{path: 'signin', component: LoginComponent},
]
}
];
export const routing = RouterModule.forChild(routes);
我有同样的问题。
我通过在路由之前添加它来修复:
this.zone.run(() => {
// Your router is here
this._router.navigate(['public/test'])
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)