angular 2 rc3路由器默认路由

时间:2016-06-30 23:27:37

标签: angular

我们正在将项目从路由器弃用到新的角度2路线。我在路由器中不能找到类似于usedefault的东西。基本上,当我加载页面时,我们希望网址更改为{{3而不是http://website_name/index

1 个答案:

答案 0 :(得分:1)

<强> RC3

您可以使用 redirectTo ,例如:

export const YourAppRoutes: RouterConfig = [
  {
    path: '',
    redirectTo: '/index',
    terminal: true
  },
  {
    path: 'index',
    component: YouMainComponent,
    children: [
      { path: '',     component: YouMainComponentList },
      { path: ':id',  component: YouMainComponentDetail }
    ]
  }
];

<强> RC4

export const YourAppRoutes: RouterConfig = [
  {
    path: '',
    redirectTo: 'index',
    pathMatch: 'full'
  },
  {
    path: 'index',
    component: YouMainComponent,
    children: [
      { path: '',     component: YouMainComponentList },
      { path: ':id',  component: YouMainComponentDetail }
    ]
  }
];

供参考:https://angular.io/docs/ts/latest/guide/router.html#!#redirect