我只是收到重定向代码调用的错误,但我应该使用我的代码进行重定向:
if (!localStorage.getItem('emp_user')) {
console.log('HELLO THERE');
this.router.navigate(['create'])
}
还有我得到的错误:
core.js:5847错误错误:未捕获(承诺):TypeError:无法 读取未定义TypeError的属性“ split”:无法读取属性 未定义的“拆分” 在defaultUrlMatcher(router.js:530) 比赛时(router.js:2718) 在ApplyRedirects.push ../ node_modules/@angular/router/fesm5/router.js.ApplyRedirects.matchSegmentAgainstRoute (router.js:2564) 在ApplyRedirects.push ../ node_modules/@angular/router/fesm5/router.js.ApplyRedirects.expandSegmentAgainstRoute (router.js:2515) 在MapSubscriber.project(router.js:2488) 在MapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / operators / map.js.MapSubscriber._next中 (map.js:35) 在MapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber.next中 (Subscriber.js:53) 在Observable._subscribe(subscribeToArray.js:5) 在Observable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable._trySubscribe中 (Observable.js:43) 在Observable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable.subscribe (Observable.js:29) 在resolvePromise(zone.js:852) 在resolvePromise(zone.js:809) 在zone.js:913 在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask (zone.js:423) 在Object.onInvokeTask(core.js:24328) 在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask (zone.js:422) 在Zone.push ../ node_modules / zone.js / dist / zone.js.Zone.runTask(zone.js:195) 在rainMicroTaskQueue上
UPD: 路线
应用路由
const routes: Routes = [
{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full',
}, {
path: '',
component: AdminLayoutComponent,
children: [{
path: '',
loadChildren: './layouts/admin-layout/admin-layout.module#AdminLayoutModule'
},
]
},
{
path: '',
loadChildren: './_user/user.module#UserModule'
},
// {path: '**', redirectTo: 'default/error/403', pathMatch: 'full'},
];
@NgModule({
imports: [
CommonModule,
BrowserModule,
RouterModule.forRoot(routes, {
useHash: true
})
],
exports: [
],
})
export class AppRoutingModule { }
管理布局。路由
import { Routes } from '@angular/router';
import { DashboardComponent } from '../../dashboard/dashboard.component';
export const AdminLayoutRoutes: Routes = [
{ path: 'dashboard', component: DashboardComponent },
{ component: ConfirmDialog }
];
user.routing
export const UserRoutes: Routes = [
{
path: '',
component: UserComponent,
children: [
{
path: '',
redirectTo: 'create',
pathMatch: 'full'
},
{
path: 'create',
component: RegistrationComponent
},
]
}
];
答案 0 :(得分:0)
更改此路径(app.routiing.ts)
{
path: '',
loadChildren: './_user/user.module#UserModule
}
到
{
path: 'user',
loadChildren: './_user/user.module#UserModule
}