首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular 9,我如何更改路由器优先级,以便商店在回家之前先显示?

Angular 9,我如何更改路由器优先级,以便商店在回家之前先显示?
EN

Stack Overflow用户
提问于 2021-04-14 14:36:46
回答 1查看 69关注 0票数 0

我想让用户在看到首页之前先看看商店,所以我需要在app-routing-module中做些什么才能让它工作,这是我到目前为止所做的。app-routing-module.ts

代码语言:javascript
复制
const routes: Routes = [
  { path: '', component: HomeComponent, data: { breadcrumb: 'Home' } },
  { path: 'test-error', component: TestErrorComponent, data: { breadcrumb: 'Test Errors' } },
  { path: 'server-error', component: ServerErrorComponent, data: { breadcrumb: 'Server Error' } },
  { path: 'not-found', component: NotFoundComponent, data: { breadcrumb: 'Not Found' } },
  { path: 'shop', loadChildren: () => import('./shop/shop.module').then(mod => mod.ShopModule), data: { breadcrumb: 'Shop' } },
  { path: 'basket', loadChildren: () => import('./basket/basket.module').then(mod => mod.BasketModule), data: { breadcrumb: 'Basket' } },
  {
    path: 'checkout',
    canActivate: [AuthGuard],
    loadChildren: () => import('./checkout/checkout.module')
      .then(mod => mod.CheckoutModule), data: { breadcrumb: 'Checkout' }
  },
  {
    path: 'orders',
    canActivate: [AuthGuard],
    loadChildren: () => import('./orders/orders.module')
      .then(mod => mod.OrdersModule), data: { breadcrumb: 'Orders' }
  },
  {
    path: 'account',
    loadChildren: () => import('./account/account.module')
      .then(mod => mod.AccountModule), data: { breadcrumb: { skip: true } }
  },
  {
    path: 'admin',
    canActivate: [AuthGuard, AdminGuard],
    loadChildren: () => import('./admin/admin.module')
      .then(mod => mod.AdminModule), data: { breadcrumb: 'Admin' }
  },
  { path: '**', redirectTo: 'not-found', pathMatch: 'full' }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-14 15:41:29

代码语言:javascript
复制
const routes: Routes = [
  ==>{ path: '', redirectTo: 'shop', pathMatch: 'full'},
  ==>{ path: 'home', component: HomeComponent, data: { breadcrumb: 'Home' } },
  { path: 'test-error', component: TestErrorComponent, data: { breadcrumb: 
    'Test Errors' } },
  { path: 'server-error', component: ServerErrorComponent, data: { breadcrumb: 
    'Server Error' } },
  { path: 'not-found', component: NotFoundComponent, data: { breadcrumb: 'Not 
    Found' } },
  { path: 'shop', loadChildren: () => import('./shop/shop.module').then(mod => 
    mod.ShopModule), data: { breadcrumb: 'Shop' } },
  { path: 'basket', loadChildren: () => 
    import('./basket/basket.module').then(mod => mod.BasketModule), data: { 
    breadcrumb: 'Basket' } },
  { path: 'checkout',
    canActivate: [AuthGuard],
    loadChildren: () => import('./checkout/checkout.module')
    .then(mod => mod.CheckoutModule), data: { breadcrumb: 'Checkout' }
  },
  { path: 'orders',
    canActivate: [AuthGuard],
    loadChildren: () => import('./orders/orders.module')
    .then(mod => mod.OrdersModule), data: { breadcrumb: 'Orders' }
  },
  { path: 'account',
    loadChildren: () => import('./account/account.module')
    .then(mod => mod.AccountModule), data: { breadcrumb: { skip: true } }
  },
  { path: 'admin',
    canActivate: [AuthGuard, AdminGuard],
    loadChildren: () => import('./admin/admin.module')
    .then(mod => mod.AdminModule), data: { breadcrumb: 'Admin' }
  },
  { path: '**', redirectTo: 'not-found', pathMatch: 'full' }
];

 @NgModule({
   imports: [RouterModule.forRoot(routes)],
   exports: [RouterModule]
 })
 export class AppRoutingModule { }

您可以在代码中添加类似以下(shown with ==>)的额外配置,以便首先向用户显示ShopPage,然后根据您的重定向逻辑将他带到HomePage

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67086652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档