1

I'd like to have localization in URL like this:

http://example.com/de -> get German locale (DE)

http://example.com/it -> get Italian locale (IT)

So I did an abstract route like this:

state('root', {
  abstract: true,
  url: '/{lang:(?:de|it)}',
});

And the home one like this:

state('root.home', {
  url: '',
});

And it works fine, but now the default root http://example.com/ is not working anymore. I need to have url: '/' working like the other ones

1 Answer 1

1

Do it manually then, but it looks hacky way.

.state('root', {
  abstract: true,
  url: '/{lang:(?:de|it)}',
  params: {
     lang: null
  },
  controller: function($stateParams, $state){
    if(!$stateParams.lang){
      $state.go('.home')
    }
  }
});
Sign up to request clarification or add additional context in comments.

2 Comments

The params: {lang: null} is what I was missing. Thanks.
No..we have set its defalut value to null if its not set.. And then we are redirecting to home state.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.