Search code examples
angularangular4-router

Angular4 routing: Dynamic string parameter in path


Passing ints as path parameters is done like

const appRoutes: Routes = [
   {
        path: 'servers/:id',
        component: ServerDetailComponent
    }]
export const routing = RouterModule.forRoot(appRoutes);

but how do I do the same with :id being a string? So that I could navigate the servers object, say, by name, instead of id, like /servers/sqlserver


Solution

  • You can send strings the same way as numbers. It makes no difference between strings or numbers.

    path: 'servers/:name',