How to create a dynamic route in angular2?

I want to create a project with a dynamic route that will only specify a name on the url, and then the route will determine the URL and create my own access to this file for display on broswer

import { Routes,RouterModule } from '@angular/router';

const routes: Routes= GetDynamicRoute();

export const routing = RouterModule.forRoot(routes);

function GetDynamicRoute(){
  var results :Array<Object> = Array<Object>();
  var page = 'GET_URL_PARAMATER';

  results.push({ path: '' ,loadChildren: 'app/tmp/home.module'});
  results.push({ path: page, loadChildren: 'app/tmp/'+page+'.module' })
  return results 
}
+4
source share
1 answer

There Routeris a function called resetConfig.

See this Github question with some plungers inside: https://github.com/angular/angular/issues/11437#issuecomment-245995186

And official docs: https://angular.io/docs/ts/latest/api/router/index/Router-class.html#!#resetConfig-anchor

+1
source

Source: https://habr.com/ru/post/1655144/


All Articles