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 β­πŸ™

Subscribe to our newsletter for more code resources and news

Adrian Matei (aka adixchen)

Adrian Matei (aka adixchen)
Life force expressing itself as a coding capable human being

routerLink with query params in Angular html template

routerLink with query params in Angular html template code snippet Continue reading