默认路由在角度 5 中不起作用

Pra*_*ana 3 javascript angular-routing angular2-routing angular angular5

我已经设置了如下所示的延迟路由,

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);
Run Code Online (Sandbox Code Playgroud)

但它总是重定向到关于路径,正如你所看到的,我已经给出了默认的发布路径。请让我知道我应该在哪里进行更正以使其正常工作。

Roc*_*st1 5

尝试:

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 { }
Run Code Online (Sandbox Code Playgroud)

然后在 app.module.ts 中导入 AppRoutingModule。

每个延迟加载模块都需要自己的 routes.ts 文件。