Thursday, 20 December 2018

How to get value from cookie/service in app-routing module

I have angular site www.domainname.com with app-routing.module and those Routes:

const routes: Routes = [
  {
    path: "homepage/:lang/:country",
    ...
  },  
  ...
  {
    path: "**",
    redirectTo: "/homepage/en/gb",
    pathMatch: "full"
  },
]

If you access the page via www.domainname.com, you will be redirected to https://ift.tt/2EDTUlG page. I will store your language preference to cookie as well as to LocaleService in angular-l10n package.

Let's say you change your language to zh-cn and it will be stored accordingly in the locale service and cookie.

If you visit next time www.domainname.com, how can I tell the app-routing module to use the lang/country value from cookie/locale service and not to redirect to the default en/gb page?



from How to get value from cookie/service in app-routing module

No comments:

Post a Comment