ionic不同view跳转到同一个

ionic不同view跳转到同一个 view并保留历史的路由设计

上代码:state 里面新加一个状态

.state("other", {
    url: "/other",
    abstract: true,
    controller: "OtherCtrl",
    template: "<ion-nav-view></ion-nav-view>",
    onEnter: function($rootScope, fromStateServ) {
        fromStateServ.setState("other", $rootScope.fromState, $rootScope.fromParams);
    }
})


对应的controller
.controller("OtherCtrl", function($scope, $state, fromStateServ) {
    $scope.backNav = function() {
        var fromState = fromStateServ.getState("other");
        if (fromState.fromState !== undefined) {
            $state.go(fromState.fromState.name, fromState.fromParams);
        } else {
            //设置没有历史的时候,默认的跳转
            $state.go("app.xxx");
        }
    };
})

保留 history 的公共方法
.factory("fromStateServ", function() {
    return {
        data: {},
        setState: function(module, fromState, fromParams) {
            this.data[module] = {
                "fromState": fromState,
                "fromParams": fromParams
            };
        },
        getState: function(module) {
            return this.data[module];
        }
    };
})

https://segmentfault.com/n/1330000004202748

posted @ 2016-11-05 16:23  小小强学习网  阅读(689)  评论(0编辑  收藏  举报