S
S
sdgroup142020-06-25 09:32:44
JavaScript
sdgroup14, 2020-06-25 09:32:44

How can an application add locale to the url?

In general, there is already a ready-made application. language detection only works from localStorage. those. the language is retrieved from the storage (or default, if empty) and set in ngx-translate. The bottom line is that it is not implemented in ur (in routes).

{
    path: 'home',
    loadChildren: './home.module#HomeModule'
 }

Those. if I add a new root route {path: ":lang"} I will have to prescribe the current language in all 100500 routerLinks.
{
    path: ':lang/home',
    loadChildren: './home.module#HomeModule'
 }

The question is, is there a way to somehow access the Router in 1 place and set the language in 1 function for all routerLinks in the entire application? It seems to me that just manually prescribing each link is not correct.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Levchenko, 2020-06-30
@nuykon

Hmm... and what's the problem with doing it instead of adding a new route, like this for example:

const lang = localStorage.getItem('lang') || 'ru';
{
    path: lang + '/home',
    loadChildren: './home.module#HomeModule'
 }

?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question