默认路由在 angular 5 中不起作用
Default route is not working in angular 5
我已经设置了延迟路由,如下所示,
const appRoutes : Routes = [
{ path : '' , redirectTo : '/posts' , pathMatch:'full' },
{ path : 'posts', component:PostsComponent , children: [
{path : 'contact' , component : ContactComponent },
{path : ':slugurl' , component : SinglepostComponent },
{path : 'category/:category' , component : PostfeedComponent },
{path : '' , component : PostfeedComponent },
]},
{ path : 'about', loadChildren : './aboutme/aboutme.module#AboutmeModule' },
{ path : 'admin', loadChildren: './admin/admin.module#AdminModule' , canActivate: [ AuthGuard ] },
{ path : 'login', loadChildren : './login/login.module#LoginModule' },]
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
但它总是重定向到关于路径,正如你所看到的,我已经将默认路由设置为 post。请让我知道我应该在哪里进行更正才能使其正常工作。
尝试:
export const appRoutes : Routes = [
{ path : '' , redirectTo : '/posts' , pathMatch:'full' },
{ path : 'posts', component:PostsComponent , children: [
{path : 'contact' , component : ContactComponent },
{path : ':slugurl' , component : SinglepostComponent },
{path : 'category/:category' , component : PostfeedComponent },
{path : '' , component : PostfeedComponent },
]},
{ path : 'about', loadChildren : './aboutme/aboutme.module#AboutmeModule' },
{ path : 'admin', loadChildren: './admin/admin.module#AdminModule' , canActivate: [ AuthGuard ] },
{ path : 'login', loadChildren : './login/login.module#LoginModule' },]
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
],
exports: [RouterModule]
})
export class AppRoutingModule { }
然后在app.module.ts中导入AppRoutingModule。
每个延迟加载模块都需要自己的 routes.ts 文件。
我已经设置了延迟路由,如下所示,
const appRoutes : Routes = [
{ path : '' , redirectTo : '/posts' , pathMatch:'full' },
{ path : 'posts', component:PostsComponent , children: [
{path : 'contact' , component : ContactComponent },
{path : ':slugurl' , component : SinglepostComponent },
{path : 'category/:category' , component : PostfeedComponent },
{path : '' , component : PostfeedComponent },
]},
{ path : 'about', loadChildren : './aboutme/aboutme.module#AboutmeModule' },
{ path : 'admin', loadChildren: './admin/admin.module#AdminModule' , canActivate: [ AuthGuard ] },
{ path : 'login', loadChildren : './login/login.module#LoginModule' },]
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
但它总是重定向到关于路径,正如你所看到的,我已经将默认路由设置为 post。请让我知道我应该在哪里进行更正才能使其正常工作。
尝试:
export const appRoutes : Routes = [
{ path : '' , redirectTo : '/posts' , pathMatch:'full' },
{ path : 'posts', component:PostsComponent , children: [
{path : 'contact' , component : ContactComponent },
{path : ':slugurl' , component : SinglepostComponent },
{path : 'category/:category' , component : PostfeedComponent },
{path : '' , component : PostfeedComponent },
]},
{ path : 'about', loadChildren : './aboutme/aboutme.module#AboutmeModule' },
{ path : 'admin', loadChildren: './admin/admin.module#AdminModule' , canActivate: [ AuthGuard ] },
{ path : 'login', loadChildren : './login/login.module#LoginModule' },]
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
],
exports: [RouterModule]
})
export class AppRoutingModule { }
然后在app.module.ts中导入AppRoutingModule。
每个延迟加载模块都需要自己的 routes.ts 文件。