Persisting query string with AngularJS routing

前端 未结 6 2209
盖世英雄少女心
盖世英雄少女心 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:34

    Here is the solution I used that caused persistent query string propagation (that I didn't want).

    el.find('li').has('ul').on('click', 'a', function (e) {
        // handle clicks manually
        e.stopPropagation();
        // if the anchor tag has a specific class
        if (el.hasClass('link')) {
            var path = el.attr('href').replace('#', '');
            scope.$apply(function () {
                // changing the path changes only the path
                // the query string is left intact
                $location.path(path);
            });
        }
    });
    

提交回复
热议问题