Closed DimaKomoff closed 3 years ago
Hello @DimaKomoff, I don't know the complete business you need but you can probably extends the LocalizeParser
to add your business. (And for example add a method to call when you want to add route (that will call this.router.resetConfig(this.routes);
)
@gilsdav hi. When the application loads, depending on certain conditions, I set up the routing settings using this.router.resetConfig (routes). But translate-router sets the setting from the default routes. Can you help me?
@gilsdav I should use somethink like this
LocalizeRouterModule.forRoot(condition ? routes : anotherRoutes, {
parser: {
provide: LocalizeParser,
useFactory: localizeFactory,
deps: [TranslateService, Location, LocalizeRouterSettings, HttpClient, TransferState]
},
cacheMechanism: 'Cookie',
cacheName: 'DEFAULT_LANGUAGE',
defaultLangFunction: languageBrowserDetection
}),
or change routing config with this.router.resetConfig
If you only need to do it once (at app start), you can use condition like you did in your latests comment or if routes comes from a service you can take a look at the httpParser implementation: https://github.com/gilsdav/ngx-translate-router/blob/master/projects/ngx-translate-router-http-loader/src/lib/http-loader.ts
load(baseRoutes: Routes): Promise<any> {
return new Promise((resolve: any) => {
this.myService.getRoutes()
.subscribe((routes: Routes) => {
this.init(routes).then(resolve);
});
});
}
How to init array of routes dynamically?