Angular 直接路由到指定页面

Angular 直接路由到指定页面,angular,angular2-routing,Angular,Angular2 Routing,我试图在最开始或空白的URL扩展上访问特定页面。比如,如果我在本地运行项目,那么当我输入localhost:4200时,我希望访问localhost:4200/pages/dashboard |-App |-Pages |-dashboard |-signIn 应用程序路由如下所示 const routes: Routes = [ { path: '', redirectTo: '/pages/dashboard', pathMatch: 'full' }

我试图在最开始或空白的URL扩展上访问特定页面。比如,如果我在本地运行项目,那么当我输入localhost:4200时,我希望访问localhost:4200/pages/dashboard

|-App
   |-Pages
       |-dashboard
       |-signIn
应用程序路由如下所示

const routes: Routes = [
  { path: '', redirectTo: '/pages/dashboard', pathMatch: 'full' },
  { path: 'pages', loadChildren: './pages/pages.module#PagesModule', canActivate: [Authentication] },
  { path: 'sign-in', component: SignInComponent }
];

export const routing: ModuleWithProviders = RouterModule.forRoot(routes, {
  preloadingStrategy: PreloadAllModules,
  useHash: false
});
imports: [
    BrowserModule,
    HttpClientModule,
    ToastrModule.forRoot(),
    routing,
    PagesModule,
    SignInModule,
  ],
页面路由就像

export const routes: Routes = [
  {
    path: '',
    component: PagesComponent,
    children: [
      {
        path: 'dashboard',
        component: DashboardComponent,
        data: { breadcrumb: 'My Dashboard' },
      }
    ]
  }
];

export const routing: ModuleWithProviders = RouterModule.forChild(routes);
App.module如下所示

const routes: Routes = [
  { path: '', redirectTo: '/pages/dashboard', pathMatch: 'full' },
  { path: 'pages', loadChildren: './pages/pages.module#PagesModule', canActivate: [Authentication] },
  { path: 'sign-in', component: SignInComponent }
];

export const routing: ModuleWithProviders = RouterModule.forRoot(routes, {
  preloadingStrategy: PreloadAllModules,
  useHash: false
});
imports: [
    BrowserModule,
    HttpClientModule,
    ToastrModule.forRoot(),
    routing,
    PagesModule,
    SignInModule,
  ],

我也面临着同样的问题,我通过改变路线来解决这个问题

PagesModule.module.ts
-----------------------
export const routes: Routes = [
  {
    path: '',
    component: PagesComponent,
    data: { breadcrumb: 'My Dashboard' }
  },
  {
    path: 'dashboard',
    component: PagesComponent,
    data: { breadcrumb: 'My Dashboard' }
  }
  }
];

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

或者尝试使用

当我们需要仪表板时,为什么要加载PagesComponent。此外,当没有任何路由与路径匹配时,while路由也会工作