Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Angular 1 UI路由器-HTML5模式参数URL始终以正斜杠结尾_Angularjs_Angular Ui Router_Html5mode - Fatal编程技术网

Angularjs Angular 1 UI路由器-HTML5模式参数URL始终以正斜杠结尾

Angularjs Angular 1 UI路由器-HTML5模式参数URL始终以正斜杠结尾,angularjs,angular-ui-router,html5mode,Angularjs,Angular Ui Router,Html5mode,我有一个基本URL为/foo/的页面,并且已将我的状态设置为需要参数 因此,如果用户点击/foo/user1/,user1是参数 是否可以同时监视这两种类型的URL?例如,我可以在相同的状态中声明/foo/user1/和/foo/user1(注意,没有正斜杠),还是需要创建另一个状态来专门监视尾部斜杠 目前,它可以是一个或另一个,但不能同时是两个。这是一个准确的陈述,还是我在文档中遗漏了什么?如果您使用的是最新版本的ui路由器请在您的配置块中添加此代码$urlmacherFactoryProvi

我有一个基本URL为/foo/的页面,并且已将我的状态设置为需要参数

因此,如果用户点击/foo/user1/,user1是参数

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


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

如果您使用的是最新版本的
ui路由器
请在您的配置块中添加此代码
$urlmacherFactoryProvider.stricmode(false)
,但对于较旧版本的
ui路由器
请添加此代码

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

您应该检查他们的区域,如果您使用的是最新版本的
ui路由器
,则有一个专门的部分用于在配置块中添加此代码
$URLMacherFactoryProvider.strictMode(false)
,但对于较旧版本的
ui路由器
添加此代码

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

你应该查看他们的区域,那里有一个专门的部分,用于

也许这就是你想要的-也许这就是你想要的-那条规则正是我想要的。我使用的是最新版本,但是$urlMatcherFactoryProvider.strictMode(false)没有执行我想要的行为。谢谢你提供了这两个选项,希望我能对这个答案投两次票!这条规则正是我想要的。我使用的是最新版本,但是$urlMatcherFactoryProvider.strictMode(false)没有执行我想要的行为。谢谢你提供了这两个选项,希望我能对这个答案投两次票!