Persisting query string with AngularJS routing

前端 未结 6 2078
盖世英雄少女心
盖世英雄少女心 2021-01-05 18:11

I\'ve been working on a large Angular app for almost a year now and I\'m stuck trying to do what I expected to be trivial.

Here are two routes I have with params (sh

6条回答
  •  孤街浪徒
    2021-01-05 18:38

    I'm not sure if you would consider this a better solution than what you've got, but it is a solution.

    In your initialization code, add the following:

    app.run(["$rootScope", function ($rootScope) {
        $rootScope.$on("$routeChangeSuccess", function (e, current) {
            $rootScope.query = $.param(current.params);
        });
    }]);
    

    Then, in your HTML, make your links as follows:

    Navigate to B
    

提交回复
热议问题