default inactive state for ui-router-extras

2019-05-30 21:24发布

I am using ui-router-extras to support parallel state for modal windows. When an modal window is open, the "home" state become inactive, but is still visible in the background. This allows me to have deep link for each modal windows.

However, I am having trouble figure out a good way to set the "default" inactive state to "home" if an user come through a modal window link.

I currently define my states like this:

$stateProvider
.state('signup', {
    url: '/signup',
    onEnter: function($modal) {
        $modal.open({
            templateUrl: 'singup.html',
            size: 'large',
            controller: 'SignUpController'
        });
    }
})

2条回答
做个烂人
2楼-- · 2019-05-30 21:35

check out ui-router-extras release 0.0.12 and above. I've added support for default substates in DSR. See this github issue for details:

https://github.com/christopherthielen/ui-router-extras/issues/150

And read the updated API docs here: http://christopherthielen.github.io/ui-router-extras/#/dsr

var myState = {
    name: 'foo',
    url: '/foo/:fooID/:barID',
    template: '<div></div>,
    controller: 'fooCtrl',
    deepStateRedirect: {
        default: { state: "foo.bar.baz.defaultSubState", params: { defaultStateParam1: "99" } }
    }
}
查看更多
疯言疯语
3楼-- · 2019-05-30 21:43

You only posted one state definition! I tried to get the same working and finally figured it out. If you found a solution could you post it? If not please provide more details

Maybe my solution will help

angular.module('xbmcremoteApp')
    .config(function ($stateProvider,$stickyStateProvider) {
        $stickyStateProvider.enableDebug(true);
        $stateProvider
            .state('movies', {
                abstract: true,
                url: '/movies',
                templateUrl: 'app/movies/movies.html',
                controller: 'MoviesCtrl'
            }).state('movies.gallery', {
                url: '',
                templateUrl: 'app/movies/movies-gallery/movies-gallery.html',
                controller: 'MoviesGalleryCtrl',
                sticky:true
            }).state('movies.gallery.details', {
                url: '/:id',
                onEnter: ['$stateParams', '$state', '$modal', '$resource', function ($stateParams, $previousState, $modal, $resource) {
                    $modal.open({
                        templateUrl: 'app/movies/movies-gallery/myModalContent.html',
                        resolve: {
                            id: function () {
                                $stateParams.id
                            }
                        },
                        size:'lg',
                        controller: 'ModalInstanceCtrl'
                    }).result.then(function () {

                                return  $previousState.go("movies.gallery");

                        });
                }]
            });
    });
查看更多
登录 后发表回答