2

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 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

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
Thank you Doron..they are changing so fast
I've included also the code for RC4 (with @angular/router: 3.0.0-beta.1)
I think you also need pathMatch: full for path: '' or terminal:true in RC3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.