0

I'm using ui-router 0.2.18

Main referral admin URL for my website looks like this http://example.com/partners/dashboard I want it to be changed to http://example.com/partners/dashboard#referral-link (to bootstrap corresponding ui-router's state: referral-link). But it seems that when method does not work...

app.js

.config(['$stateProvider', '$urlRouterProvider', 
    function($stateProvider, $urlRouterProvider) {

    // it does not work...
    $urlRouterProvider.when('/partners/dashboard', '/partners/dashboard#/referral-link');

    var referralLinkState = {
        name: 'referral-link',
        url: '/referral-link',
        template: '<kr-partners-referral-link></kr-partners-referral-link>'
    };

    var myClientsState = {
        name: 'my-clients',
        url: '/my-clients',
        template: '<kr-partners-my-clients></kr-partners-my-clients>'
    };
    // ...
    $stateProvider.state(referralLinkState);
    $stateProvider.state(myClientsState);    
}]);  

ADDED LATER: Guys, I think your .otherwise method will not work for me. Because it will override all URLs, but I need to override only one specific URL.

yaru
  • 1,260
  • 1
  • 13
  • 29

2 Answers2

0

Use .otherwise clause with string argument:

$urlRouterProvider.otherwise('/referral-link');

Or with callback for dynamic:

$urlRouterProvider.otherwise(function($injector) {
    var $state = $injector.get("$state");
    $state.go(..put state name here);
});
YD1m
  • 5,845
  • 2
  • 19
  • 23
0

The answer is here: https://stackoverflow.com/a/22569209/1056253

Basically what I did - is injected $state inside /partners/dashboard controller and called its go method like so: $state.go('referral-link');

Community
  • 1
  • 1
yaru
  • 1,260
  • 1
  • 13
  • 29