我有一个基本 URL 为 /foo/ 的页面,并设置了我的状态以期望一个参数。
所以,如果用户点击 /foo/user1/,user1就是参数。
是否可以同时查看这两种类型的网址?例如,我可以将 /foo/user1/ 和 /foo/user1(注意,没有正斜杠)声明为相同的状态,还是需要创建另一个状态来专门监视尾部斜杠?
目前,它可以是其中之一,但不能两者兼而有之。这是一个准确的陈述,还是我在文档中遗漏了什么?
我有一个基本 URL 为 /foo/ 的页面,并设置了我的状态以期望一个参数。
所以,如果用户点击 /foo/user1/,user1就是参数。
是否可以同时查看这两种类型的网址?例如,我可以将 /foo/user1/ 和 /foo/user1(注意,没有正斜杠)声明为相同的状态,还是需要创建另一个状态来专门监视尾部斜杠?
目前,它可以是其中之一,但不能两者兼而有之。这是一个准确的陈述,还是我在文档中遗漏了什么?
如果您ui-router
在配置块中使用最新版本的 add this $urlMatcherFactoryProvider.strictMode(false)
但对于旧版本的ui-router
add 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 + '/';
});