Search code examples
angularangular2-routingangular2-router

Route to non-empty default route in angular 2


One way to define a default routes with the new RC router is

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

but how can I show initially a page with a non-empty path? like

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

that will never show the home content, but I want it.

How can this be done in the new RC1 router ?


Solution

  • >= RC.4

    { path: '', redirectTo: '/home', pathMatch: 'full' }
    { path: '/home',  component: Home }
    

    <= RC.2

    useAsDefault is not yet supported in the new router. Create a dummy component for the / route that forwards to /home

    export class DummyComponent {
      constructor(private router:Router) {
        setTimeout(() => this.router.navigate('/home'));
      }
    }
    

    There is also currently no option to skip adding the navigation to the history which might cause issues with the back button.

    The router issues are being worked on...