小编Tim*_*nko的帖子

Angular 2路由重定向到子路由

我是Angular 2的新手.我想为我的应用程序的每个部分创建独立的模块.例如,我使用默认组件AuthComponent创建了AuthModule,其中包含其子组件(SignIn或SignUp)的路由器插座.所以我想实现以下场景:

  1. 导航到/ - root off app - 重定向到/ auth
  2. 重定向到/ auth后 - 用路由器插座加载AuthComponent
  3. 加载AppComponent后 - 通过重定向到/ auth/sign-in加载默认登录组件

但是当我去localhost /我得到重定向到/ auth我想要的东西,但下一次重定向到登录不会出现.

我的代码:app.routing

const routes: Routes = [
  {
      path: '', 
      redirectTo: '/auth', 
      pathMatch: 'full'
  }
];

export const appRouting: ModuleWithProviders = RouterModule.forRoot(routes);
Run Code Online (Sandbox Code Playgroud)

auth.routing

const routes: Routes = [
  {
    path: 'auth',
    component: AuthComponent,
    children: [
      {
         path: '', 
         redirectTo: 'sign-in', 
         pathMatch: 'full'
      },
      {
         path: 'sign-in', 
         component: SignInComponent
      }
    ]
  },

];

export const authRouting: ModuleWithProviders = RouterModule.forChild(routes);
Run Code Online (Sandbox Code Playgroud)

auth.component.html

<div …
Run Code Online (Sandbox Code Playgroud)

routing children angular

29
推荐指数
3
解决办法
4万
查看次数

标签 统计

angular ×1

children ×1

routing ×1