Corbfon
Corbfon

Reputation: 3644

Angular 2 Router: route everything behind a certain route

We're creating a new version of an app, and need to keep legacy routes working. Legacy urls come into our app under a specific route, let's call it legacy.

So, if a route is /legacy/route1, I am going to handle it with a Resolver to tell where it's actually supposed to go within our app (the old url routing scheme is very convoluted and needs quite a bit of logic). However, if it comes in under /legacy/route1/subroute3/somethingelse, I'd like to handle it with the same resolver.

How do I catch all of these routes within a single or a couple of lines in my RouterModule? I've tried all of the below:

{ path: 'legacy', component: Legacy, resolve: [LegacyRouteResolver] },
{ path: 'legacy/', component: Legacy, resolve: [LegacyRouteResolver] },
{ path: 'legacy/*', component: Legacy, resolve: [LegacyRouteResolver] },
{ path: 'legacy/**', component: Legacy, resolve: [LegacyRouteResolver] }

but none of them will give me any routes that come in with multiple slashes, and there are many other circumstances under which they fail (the octothorp seems to throw them off, too)

Upvotes: 2

Views: 1132

Answers (1)

Madhu Ranjan
Madhu Ranjan

Reputation: 17944

you can use below,

 { 
     path: 'legacy',
     children: [
        {path : '**' , component: Legacy}
     ]
  }

this will match all the routes after legacy

Hope this helps!!

Upvotes: 2

Related Questions