Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 
}
like image 656
Dara Vichit Avatar asked Nov 08 '22 08:11

Dara Vichit


1 Answers

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

like image 140
slaesh Avatar answered Nov 15 '22 06:11

slaesh