1

If I go to the webpage www.abc.com/index.html?state=register

Is there a way with ui-router that I can make it go directly to the state:

$state.transitionTo("auth.content", { content: "register" })

Note that if the user enters www.abc.com then I want them to go to the normal page that is set up with a / state.

Thanks

Alan2
  • 23,493
  • 79
  • 256
  • 450

1 Answers1

1

I would say, your SPA (single page application) will have to always reach the index.html first (related to your prev question). The rest is done by angular, by UI-Router - but all will and must start at index.html

And the we can use UI-Router

  • .otherwise() or
  • .when()

settings of the $urlRouterProvider. The way how to achieve that is described here:

Angular UI-Router $urlRouterProvider .when not working *anymore*

so basically we can use .when()

var whenConfig = ['$urlRouterProvider', function($urlRouterProvider) {

    $urlRouterProvider
      .when('/app/list', ['$state', 'myService', function ($state, myService) {
            $state.go('app.list.detail', {id: myService.Params.id});
    }])
    .otherwise('/auth/content');
}];
...
app.config(whenConfig) 

but the version 2.0.13 has some issues and the solution is described here:

Angular UI-Router $urlRouterProvider .when not working when I click

Where is shown that we have to use some fix for .when() like:

var onChangeConfig = ['$rootScope', '$state',
 function ($rootScope, $state) {

  $rootScope.$on('$stateChangeStart', function (event, toState) {    
    if (toState.name === "app.list") { 
      event.preventDefault();
      $state.go('app.list.detail', {id: 2});
    }
  });

}]
Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • @Radmin - Thanks. If you don't mind could you also add a solution with a few lines that are specific to my other question so it might help others. The proposed answer for that question does not really address anything about the changes that are needed to ui-router but your answer does. – Alan2 Jan 15 '15 at 11:11
  • 1
    Will gladly do... I almost have that ... ;) – Radim Köhler Jan 15 '15 at 11:24