Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 5 localize-router set route with country/lang code

Here is my problem. I have to set up routing in Angular so that in URL there will be a country code and a language. for example

https://example.com/usa/en

The tricky part is that this localization parts can change so I have a button to switch country and language so it will be /gb/en or /usa/fr.

How can I get it working like this using localize-router and ngx-translate.

Any help much appreciated.

like image 996
Piotr Smyda Avatar asked Aug 24 '18 08:08

Piotr Smyda


1 Answers

Pardon me if I got your question wrong, but if I understand it correctly you can follow below approach:

In your AppRoutingModule configure routes as below:

const routes: Routes = [
  { 
     path:'' , pathMatch: 'full', component: SomeComponent,
     children: [
        { path: ':country-code/:lang-code' , component: SomeOtherComponent }
     ]
  }
]

You can now redirect by your button click event and it changes country-code and lang-code accordingly and you can retrieve these values in your SomeOtherComponent to perform related tasks.

like image 139
Kalpesh Shingala Avatar answered Oct 15 '22 05:10

Kalpesh Shingala