Different urls for same state in ui-router in angularjs

Can we have different urls configured for same state in angularjs. For example,
I need to use /url-a and /url-b ,use same states in angularjs.

1 Like

Yes indeed, a primitive way to get you started is just to double-up on your providers:

.config(function($routeProvider, $locationProvider) {
  $routeProvider
   .when('/url-a', {
    templateUrl: 'url.html',
    controller: 'UrlController',
  })
   .when('/url-b', {
    templateUrl: 'url.html',
    controller: 'UrlController',
  });
1 Like

Thanks for the reply.
I am using state provider and i guess if we use something similar, i get the following error,

Failed to instantiate module app due to:
Error: State ‘’ is already defined

.state(‘app.state’, {
url: “/url-a”,
templateUrl: ‘url.html’,
controller: ‘UrlController’,
})
.state(‘app.state’', {
url: “/url-b”,
templateUrl: ‘url.html’,
controller: ‘UrlController’,
})

To make this work, for each different url , i need to define a new state in config router like this,
.state(‘app.stateA’, {
url: “/url-a”,
templateUrl: ‘url.html’,
controller: ‘UrlController’,
})
.state(‘app.stateB’', {
url: “/url-b”,
templateUrl: ‘url.html’,
controller: ‘UrlController’,
})

Is there any way we can dynamically load the states, based on the url or any other solution?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.