AngularJs UI router - one state with multiple URLs

前端 未结 5 931
醉话见心
醉话见心 2020-12-28 13:58

I have a request to add in another URL parameter that directs to a state that I already have set up. For efficiency purposes, I\'m trying to see if I can add multiple URLs t

5条回答
  •  太阳男子
    2020-12-28 14:50

    I had almost the same problem, only with another constraint - I didn't want to use a redirect, since I wanted the url in the browser to stay the same, but display the same state.
    This was because I wanted the chrome saved passwords to work for users that already saved the previous url.

    In my case I wanted these two urls :
    /gilly and
    /new/gilly
    to both point to the same state.

    I solved this by having one state defined for /gilly, and for the second url, I defined an abstract state called /new.

    This should be set up like this :

    $stateProvider.state('new', {
        abstract: true,
        url: '/new'
        template: '',
        controller: function() { }
    }).state('gilly', {
        url: '/gilly',
        template: 'gilly.html',
        controller: 'GillyController'
    }).state('new.gilly', {
        url: '/gilly',  // don't add the '/new' prefix here!
        template: 'gilly.html',
        controller: 'GillyController'
    });
    

提交回复
热议问题