带辅助插座的Angular2布线

时间:2016-09-15 15:23:19

标签: angular angular2-routing

我的目录结构如下:

my-app
  |- src
    |- app
      |- private
        |- private.routing
      |- public
        |- public.routing
      app.routing

private.routing文件:

export const routing: ModuleWithProviders = RouterModule.forChild([
  { path: '', component: PrivateComponent, children: [
    { path: 'header', component: HeaderComponent, outlet: 'auxheader' },
    { path: 'dashboard', component: DashboardComponent }
  ]},
]);

app.routing文件:

import { ModuleWithProviders }  from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

export const routes: Routes = [
  { path: '', redirectTo: 'public', pathMatch: 'full' },
  { path: 'public', loadChildren: 'app/public/public.module#PublicModule' },
  { path: 'private', loadChildren: 'app/private/private.module#PrivateModule' }
];

export const routing: ModuleWithProviders = RouterModule.forRoot(routes);

在公共目录中的组件中,我尝试在成功验证后私下导航到组件。

如果我使用this.route.navigateByUrl('/private/dashboard');它可行,但使用this.route.navigateByUrl('/private/(dashboard//auxheader:header)');失败并出现以下错误Cannot match any routes: 'private'

我哪里错了?

2 个答案:

答案 0 :(得分:0)

您必须更正网址

this.route.navigateByUrl('/private/dashboard(auxheader:header)');

希望这会有所帮助!!

答案 1 :(得分:0)

如上所述:你的道路是错误的。正确的导航路径应该是:

/private/(auxheader:account)