Use wildcard to redirect to main sub-route component in angular

Project: bookmarks.dev - 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.bookmarks.dev/snippets/60046e4554aac471e0799da7/some-mongo-title-here will still “point” to https://www.bookmarks.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 Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Subscribe to our newsletter for more code resources and news

Adrian Matei

Adrian Matei
Life force expressing itself as a coding capable human being

Mongo create full text index example

Code snippets showing how to create a mongo create full text index and how to search for results with its help. Continue reading

Mongo full text search example

Published on February 07, 2021

Mongoose query pagination example

Published on February 05, 2021