Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi url for states (e.g. multilingual) #119

Closed
vizo opened this issue Oct 5, 2014 · 5 comments
Closed

Multi url for states (e.g. multilingual) #119

vizo opened this issue Oct 5, 2014 · 5 comments
Labels

Comments

@vizo
Copy link

vizo commented Oct 5, 2014

Is there a way to define multi urls for state?
I am searching for this solution for a long time ... i made plugin for ui-router, custom url matcher ... but it's a little bit hacky and every new version i must update it... you can check it how it works on http://naslovnice.si.

I guess it would be so easy if route parameter could be also a function e.g.:

route: function($state, resolvedLocale, otherResolvedVar, ...) {
  // In functions for generating urls (e.g. $state.url), uses param locale if passed,
  // else uses resolved locale to return right url...
  var locale = $state.params.locale || resolvedLocale; 
  switch (locale) {
    default:
    case 'en':
      return '/en/home';
    break;
    case 'sl':
      return '/sl/domov';
    break;
  }
}

This could also be used for state's url aliases ...

What do you think?

@vizo vizo changed the title Aliases Multi url for states (e.g. multilingual) Oct 5, 2014
@jeme
Copy link
Contributor

jeme commented Oct 5, 2014

You can use the route provider: https://github.com/dotJEM/angular-routing/wiki/Route-provider---basic-configuration for aliased states

angular.module('phonecat', ['dotjem.routing']).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider
      .when('/phones', { state: 'phones' })
      .when('/otherphones', { state: 'phones' });
}]);

As for your example of locales, I would make locale a parameter (/{locale}/home

@jeme jeme added the question label Oct 5, 2014
@vizo
Copy link
Author

vizo commented Oct 5, 2014

As i understand, in this case, i can redirect different urls to same state. e.g.:

angular.module('phonecat', ['dotjem.routing']).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider
      .when('/{locale}/phones', { state: 'phones'})
      .when('/{locale}/telefoni', { state: 'phones'})
}]);

But what about reverse, generating urls with $state.url ?

@jeme
Copy link
Contributor

jeme commented Oct 5, 2014

You may configure the primary URL on the state, and that will be used when using $state.url...

@vizo
Copy link
Author

vizo commented Oct 5, 2014

Maybe you didn't understand my point. I want to generate seo multilingual urls (optimizing for search engines)

@jeme
Copy link
Contributor

jeme commented Oct 6, 2014

That is safe to say, out of the scope of the router, as it would be a very complex scenario and there are more prioritized things atm... getting ready for 1.3 being one thing.

If you could settle for having just one active route set at one time. (so when en. is selected only those routes are available)... You could look into loading states dynamically.

See #19

And use $state.reinitialize whenever you change locale... That is the best built in thing I can think of... Otherwise you will need to use $route.format your self.

@jeme jeme closed this as completed Mar 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants