【问题标题】:Angularjs - $location.path with slashes in urlAngularjs - $location.path 在 url 中带有斜杠
【发布时间】:2014-12-28 17:18:46
【问题描述】:

是否可以指定 $location.search 以在 url 中发送带有斜杠的参数?

这是我的状态:

.state('home/room', {
                url: '/:home_id/:room_id',
                templateUrl: 'home/layout.html'
            });

使用链接可以完美运行:

<a ui-sref="home/room({home_id:20, folder_id: 608})"> // I get url: "/20/608" 

是否可以用 $location.path 做同样的事情?

我试过了,但它不起作用。

$location.path("home/room({home_id:20, room_id: 608})")

$location.search({home_id: 20, room_id: 608});

我收到/?home_id=20&amp;room_id=608

但我想要/20/608

我试图避免使用正则表达式。任何想法 ?谢谢

【问题讨论】:

    标签: angularjs url path angular-ui-router slash


    【解决方案1】:

    您使用的功能特定于 angular-ui-router。要使用 $location 使 URL 正确,您可以进行字符串连接来构建 URL。

    $location.path("home/room"+homeId+"/"+roomId);
    

    在使用angular-ui-router和$stateProvider时,建议使用$state.go()的angular-ui-router功能进行状态转换

    $state.go('home/room',{home_id:20, folder_id: 608});
    

    【讨论】:

    • 另见:ui-sref 指令
    猜你喜欢
    • 2020-02-17
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    相关资源
    最近更新 更多