0

我有一个基本 URL 为 /foo/ 的页面,并设置了我的状态以期望一个参数。

所以,如果用户点击 /foo/user1/,user1就是参数。

是否可以同时查看这两种类型的网址?例如,我可以将 /foo/user1/ 和 /foo/user1(注意,没有正斜杠)声明为相同的状态,还是需要创建另一个状态来专门监视尾部斜杠?

目前,它可以是其中之一,但不能两者兼而有之。这是一个准确的陈述,还是我在文档中遗漏了什么?

4

1 回答 1

2

如果您ui-router在配置块中使用最新版本的 add this $urlMatcherFactoryProvider.strictMode(false)但对于旧版本的ui-routeradd this code

$urlRouterProvider.rule(function ($injector, $location) {
    var path = $location.url();

    // check to see if the path already has a slash where it should be
    if (path[path.length - 1] === '/' || path.indexOf('/?') > -1) {
        return;
    }

    if (path.indexOf('?') > -1) {
        return path.replace('?', '/?');
    }

    return path + '/';
});

您应该查看他们的常见问题解答区域,有一个专门的斜杠部分

于 2016-08-25T05:52:09.823 回答