0
[{
    path: 'menu',
    component: MenuComponent
  },
  {
    path: 'how',
    component: HowItWorksComponent
  },
  {
    path: '',
    pathMatch: 'prefix',
    redirectTo: 'menu'
  }]

Above is my root route config why my all routes are not redirected to the menu because empty string should be a prefix to all routes. It shows respective components on /how and /menu and perfectly redirects to menu on / but it should always redirect to /menu shouldn't it?

IAmKale
  • 3,146
  • 1
  • 25
  • 46
mdanishs
  • 1,996
  • 8
  • 24
  • 50

2 Answers2

0

You have to set useAsDefault on /menu.

[{
   path: 'menu',
   component: MenuComponent,
   useAsDefault: true,
},
...
Oluwafemi Sule
  • 36,144
  • 1
  • 56
  • 81
  • I don't get the point, why should I? According to victor's post http://vsavkin.tumblr.com/post/146722301646/angular-router-empty-paths-componentless-routes this should always mount the menu component – mdanishs May 23 '17 at 21:02
  • infact any 404 should also be redirected to menu – mdanishs May 23 '17 at 21:07
0

If you want your last path to catch anything that the first two don't, then you'll want:

{
  path: '**',
  redirectTo: 'menu'
}

As explained in the angular docs, ** is a special wildcard route

John
  • 9,249
  • 5
  • 44
  • 76