Friday, March 23, 2018

Use a double asterisk in Angular routing to make a catchall wildcard that will honor all possible routes.

import { Routes, RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';
import { MyComponent } from './my.component';
 
export const MyRoutes: Routes = [
   {
      path: '**',
      component: MyComponent,
      children: []
   }
];
 
@NgModule({
   imports: [
      RouterModule.forChild(MyRoutes)
   ],
   exports: [RouterModule]
})
 
export class MyModule {
 
}

 
 

Catchall made me think of catchall email addresses wherein you could sent to any random email address at a domain name back at the beginning of the millennium and it would route through to a particular email address for that domain name. These wildcards fell out of fashion. I remember Ted Hatfield of PrismNet explaining to me why these were bad yet I cannot recall the specific reason.

No comments:

Post a Comment