Use wildcard to redirect to main sub-route component in angular
Project: codever
- File: public-routing.module.ts
The **
wildcard has to be defined as a child of the root you want redirected back to. Thus URLs like https://www.codever.dev/snippets/60046e4554aac471e0799da7/some-mongo-title-here will still βpointβ to https://www.codever.dev/snippets/60046e4554aac471e0799da7:
{
path: 'snippets/:id',
component: PublicSnippetDetailsComponent,
children: [
// This is a WILDCARD CATCH-ALL route that is scoped to the "/snippets/:snippetid"
// route prefix. It will only catch non-matching routes that live
// within this portion of the router tree.
{
path: '**',
component: PublicSnippetDetailsComponent
}
]
},
Reference - https://angular.io/guide/router#setting-up-redirects
Shared with from Codever.
π Use the Copy to mine
functionality to copy this snippet to your own personal collection and easy manage
your code snippets.
Codever is open source on Github βπ