2

I made a small project using angular CLI but i don't know how to declare default route in CLI. I used '/' for parent component and it works but if i use '/' for child component it does not work.

My parent.component.ts is:

@Routes([
  { path: '/', component: LoginComponent },
])   

parent.component.html is:

<a [routerLink]="['/Login']"></a>
<router-outlet></router-outlet>

child.component.ts is:

@Routes([
    { path: '/', component: DashboardComponent},
])

child.component.html is:

<li class="treeview">
    <a [routerLink]="['']">Dashboard</a>
</li>
<router-outlet></router-outlet>

This method works with parent and child both but i want a route with another path e.g. "/dashboard" as default. Is there any way to define default route in child component.

4

2 回答 2

2

我想你必须试试这个: -

export const HomeRoutes: RouterConfig = [
    { path: '', redirectTo: '/home', terminal: true},
    { path: 'home', component: HomeComponent, terminal: true }
];

PS:-未测试 此答案的信用

更新

您也可以尝试像这样定义您的路线两次:-

{ path: '/', component: HomeComponent}
{ path: 'home', component: HomeComponent}

这样一来,同一组件就有了默认路由器和命名路由器。

希望可以帮助你。

于 2016-06-30T09:40:52.900 回答
1

Put this option in your route config

{ ...,  terminal: true}
于 2016-06-30T09:31:47.740 回答