为什么重定向到在角路由中不起作用?

时间:2019-03-06 09:35:42

标签: angularjs angular-routing angular-router

这是我的 routerModule ,我要重定向空白页(第一页)应该是 Maincompoenent 的第一个子级。什么时候在浏览器中尝试它什么都没有显示,但是当我尝试 / web 时,它显示了该页面。

export const rootRouterConfig: Routes = [
{ path: '', redirectTo: '/web', pathMatch: 'full' },
{ 
path : '',
component : MainComponent,
children: [

  {
    path : 'web',
    loadChildren: './shop/shop.module#ShopModule'
  },
  { 
    path: 'pages',
    loadChildren: './pages/pages.module#PagesModule'
  },
  { 
    path: 'blog',
    loadChildren: './blog/blog.module#BlogModule'
  }
]
},
{ 
  path: '**', 
  redirectTo: 'web'
 }
];

这是shop模块,我想重定向到第一条路线并用作网站的主页

const路由:路由= [

    { 
      path: '',

      component: HomeFiveComponent,

    },

    {
      path: 'left-sidebar/collection/:category',
      component: CollectionLeftSidebarComponent
    },
    {
      path: 'right-sidebar/collection/:category',
      component: CollectionRightSidebarComponent
    },
    {
      path: 'no-sidebar/collection/:category',
      component: CollectionNoSidebarComponent
    },
    {
      path: 'left-sidebar/product/:id',
      component: ProductLeftSidebarComponent
    },
    {
      path: 'right-sidebar/product/:id',
      component: ProductRightSidebarComponent
    },
    {
      path: 'no-sidebar/product/:id',
      component: ProductNoSidebarComponent
    },
    {
      path: 'col-left/product/:id',
      component: ProductColLeftComponent
    },
    {
      path: 'col-right/product/:id',
      component: ProductColRightComponent
    },
    {
      path: 'column/product/:id',
      component: ProductColumnComponent
    },
    {
      path: 'accordian/product/:id',
      component: ProductAccordianComponent
    },
    {
      path: 'left-image/product/:id',
      component: ProductLeftImageComponent
    },
    {
      path: 'right-image/product/:id',
      component: ProductRightImageComponent
    },
    {
      path: 'vertical/product/:id',
      component: ProductVerticalTabComponent
    },
    {
      path: 'search',
      component: SearchComponent
    },
    {
      path: 'wishlist',
      component: WishlistComponent
    },
    {
      path: 'compare',
      component: ProductCompareComponent
    },
    {
      path: 'cart',
      component: CartComponent
    },
    {
      path: 'checkout',
      component: CheckoutComponent
    },
    {
      path: 'checkout/success',
      component: SuccessComponent
    }
  ];

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

2 个答案:

答案 0 :(得分:0)

I think this you need to specify where to redirect it in 'children'. Here you find the redirect snippets. This may help you.

答案 1 :(得分:0)

这可能是一个老问题,但是您在重定向网址中有一个“ /”,您应该将其删除,并且可以使用。

{ path: '', redirectTo: 'web', pathMatch: 'full' },

对于可能像我这样迷失于此问题的其他人,请始终确保重定向位于顶部。