Angular 1 UI-路由器 - HTML5 模式参数 URL 总是以正斜杠结尾

Angular 1 UI-Router - HTML5 Mode param URL to always end with a forward slash

我有一个页面,其基数 URL 为 /foo/ 并且已将我的状态设置为期望参数。

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

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

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

如果您使用的是最新版本的 ui-router,请在您的配置块中添加此代码 $urlMatcherFactoryProvider.strictMode(false),但对于旧版本的 ui-router,请添加此代码

$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 + '/';
});

你应该看看他们的 FAQ area, there is a dedicated section for trailing slash