We are moving out project from router deprecated to the new angular 2 route.I can't find something Similar to usedefault in the router deprecated.Basically when I load the page we want the url to change to http://website_name/index instead of http://website_name/
1 Answer
RC3
You can use redirectTo, something like :
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 }
]
}
];
for reference : https://angular.io/docs/ts/latest/guide/router.html#!#redirect
4 Comments
Doron Brikman
They change it a little bit now with the beta, use pathMatch: true instead of terminal. And also their is not need in / in redirectTo
user6535770
Thank you Doron..they are changing so fast
Gabi
I've included also the code for RC4 (with @angular/router: 3.0.0-beta.1)
Günter Zöchbauer
I think you also need
pathMatch: full for path: '' or terminal:true in RC3