Angular ui-sref encode parameter

后端 未结 3 1228
Happy的楠姐
Happy的楠姐 2020-12-10 06:09

My router looks like that:

.state(\'project\', {
        \'url\': \'/project/*path\',
        \'controller\': \'ProjectController\',
        \'templateUrl\':         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 06:33

    To resolve this problem you can change a state by using $location.path(), which has slashes in stateparams. For example if our state is like this:

    app.js

    .state('project', {
        'url': '/project/*path',
        'controller': 'ProjectController',
        'templateUrl': '/pages/project.html',
    });
    

    In this case path param may contains multiple slashes .If path=part1/part2 then you get route like this /project/part1%252Fpart2 by using ui-sref or $state.go(). So to get correct routing (i.e. /project/part1/part2), use $location.path() to change a state.

    HTML:

    {{label}}
    

    Controller :

    $scope.goToMyState = function () {
        var path = '/part1/part2'
        $location.path('/project' + path);
    };
    

提交回复
热议问题