I've been asked to make an app take in an optional first path segment and behave the same with/without it.
The app is a typical router-based lazy loaded angular app, and ideally I can implement some sort of middleware to allow the path to parse out the first segment( if it's a particular string, let's say 'foo') . I haven't found anything so far, but hoping something exists.
Example of desired behavior: the '/foo' would be optional and the router would only care about/implement the second set of routes (without '/foo')
/foo/bar /foo/bar/todo
/bar /bar/todo
CodePudding user response:
It turns out you can just add an additional route to match it pretty simply:
const routes = [... your routes ...]
imports: [RouterModule.forRoot([
{
path: 'foo',
children: routes
},
...routes])],
CodePudding user response:
You can use redirectTo
[{
path: 'foo/bar/:todo',
redirectTo: '/bar/:todo'
}, {
path: 'bar/:todo',
component: BarComponent
}]