0

I'm trying to add the language to the beginning of the url when missing only using $stateProvider. So if you navigate to "/products" it would became "/pt/products".

I've tried to add a param default value like this:

$stateProvider
    .state('root', {
        url: '/:lan',
        abstract: true,
        template: '<div ui-view=""></div>',
        params: { lan: 'pt' }
    });

But it doesn't have the desired effect. How is it done?

belyid
  • 841
  • 2
  • 12
  • 28
  • Do not miss this http://stackoverflow.com/q/31459394/1679310 – Radim Köhler Oct 20 '16 at 17:44
  • @RadimKöhler Yes I've checked your link and it was helpful but didn't solve my problem. I'm going to update my question based in some changes I've made that I think are in the right direction. Thank you. – belyid Oct 21 '16 at 12:48

1 Answers1

0

There are a couple of ways to do that. If you want to add this to all URLs:

$httpProvider.interceptors.push(function ($q) {
             return {
                 'request': function (config) {
                     config.url = config.url + '/en/';
                     return config;
                 }

             }
         });
     });

If you want route specific redirect:

$urlRouterProvider.when('/route',
{
  redirectTo: function () {
    return "/route/en";
  }
})
nikjohn
  • 20,026
  • 14
  • 50
  • 86