Dara Vichit
Dara Vichit

Reputation: 620

How to create dynamic route in angular2?

I want to create a project with dynamic route that only type name on url and then route will detect the url and create the own route access to that file to display to 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 
}

Upvotes: 5

Views: 4192

Answers (1)

slaesh
slaesh

Reputation: 16917

There is a function called resetConfig inside of the Router.

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

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

Upvotes: 1

Related Questions