简体   繁体   English

ui-router在进入时导航到其他状态

[英]ui-router navigate to another state onEnter

I have a wizard flow A that collects informationA 我有一个收集信息的向导流A

    states["wizard"] = {
        abstract: true,
        url: "^/wizard",
        controller: "wizardController",
        templateUrl: "wizard.html"
    };

    states["wizard.input"] = {
        url: "^/input",
        views: {
            "": {
                controller: "wizardController",
                templateUrl: "form.html"
            }
        }
    }
    states["wizard.completed"] = {
        templateUrl: "completed.html"
    };

And another wizard flow B that's the similar structure that's collecting informationB. 另一个向导流程B与收集信息B的结构类似。

What I want to do is when the user navigates to /wizard, it checks if informationB is filled, if not, navigate to fill informationB first and then navigate back to /wizard to continue the wizardA. 我想做的是当用户导航到/ wizard时,它检查是否填充了informationB,如果不是,请首先导航以填充informationB,然后再导航回/ wizard以继续向导A。

What's the best way to do the redirection when the user navigates to /wizard and the best way to return to /wizard when wizardB finishes? 当用户导航到/ wizard时进行重定向的最佳方法是什么,而向导B完成后返回到/ wizard的最佳方法是什么?

For the return I could pass some param in the url and in the wizardB controller check to see if it needs to go to wizardA, but couldn't quite figure out how to do the first redirect. 作为返回,我可以在url中传递一些参数,并在WizardB控制器中检查它是否需要进入WizardA,但不能完全弄清楚如何进行第一次重定向。

Thanks in advance. 提前致谢。

Thanks charlietfl for the information, use resolve to process redirect looks good! 感谢charlietfl提供的信息,使用resolve处理重定向看起来不错! Here's how I end up doing: 这就是我最终要做的事情:

var redirect = (returnState: string) => {
        return ['$q', '$timeout', '$state', 'dataModel', ($q, $timeout, $state, dataModel) => {
                var deferred = $q.defer();
                $timeout(() => {
                    if (dataModel.informationB === "") {
                        $state.go('wizardB.input', { rs: returnState });
                        deferred.reject();
                    } else {
                        // everything is fine, proceed
                        deferred.resolve();
                    }
                });

                return deferred.promise;
            }
        ];
    }

and in the state config: 并在状态配置中:

    resolve: {
            redirect: redirect("wizardA.input")
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM