简体   繁体   English

如何将Angular UI路由器配置为不使用严格的URL匹配模式

[英]How to config Angular ui-router to not use strict URL matching mode

ui-router's version 0.2.11 introduced option to turn off strict URL matching , but I can't figure out how to actually use it. ui-router的0.2.11版本引入了关闭严格的URL匹配的选项 ,但我不知道如何实际使用它。

I've tried standard config as they use in tests : 我已经尝试过在测试中使用的标准配置:

app.config(function ($urlMatcherFactoryProvider) {
  $urlMatcherFactoryProvider.caseInsensitive(true);
  $urlMatcherFactoryProvider.strictMode(false);
});

None of those settings work, so I guess I'm either doing something wrong or it's bugged. 这些设置都不起作用,所以我想我是在做错什么还是做错了。 There's also seem to be no documentation about it. 似乎也没有关于它的文档。

I believe this was fixed in 0.2.12. 我相信这已在0.2.12中修复。

That said, I ran into this problem in 0.2.15. 也就是说,我在0.2.15中遇到了这个问题。 It turns out that you need to configure the $urlMatcherFactoryProvider BEFORE the $stateProvider . 事实证明,您需要在$urlMatcherFactoryProvider之前配置$stateProvider

ie the following code will NOT work: 即以下代码将不起作用:

$stateProvider.state('login', {
    url: "/login",
    templateUrl: 'templates/login.html',
    controller: 'loginController as loginCtrl'
});
$urlMatcherFactoryProvider.caseInsensitive(true);
$urlMatcherFactoryProvider.strictMode(false);

You have to configure the $urlMatcherFactoryProvider first, like this: 您必须先配置$urlMatcherFactoryProvider ,如下所示:

$urlMatcherFactoryProvider.caseInsensitive(true);
$urlMatcherFactoryProvider.strictMode(false); 
$stateProvider.state('login', {
    url: "/login",
    templateUrl: 'templates/login.html',
    controller: 'loginController as loginCtrl'
});

use like this 这样使用

app.config(["$routeProvider", "$locationProvider",
    function ($routeProvider, $locationProvider) {
        return $routeProvider.when("/", {
            redirectTo: "/signin"
        })
        .when("/dashboard", {
            templateUrl: "App/views/Dashboard/dashboard.html",

        }).when("/signup", {
            templateUrl: "App/views/signup/signup.html",
            resolve: {
                permission: function (authorizationService, $route) {
                    return authorizationService.permissionCheck("signup");
                },
            }
        })
.when("/myAccount", {
            templateUrl: "App/views/myAccount/myAccount.html",
            resolve: {
                permission: function (authorizationService, $route) {
                    return authorizationService.permissionCheck("myAccount");
                },
            }
        })
        .when("/signin", {
            templateUrl: "App/views/signin/signin.html",
            resolve: {
                permission: function (authorizationService, $route) {
                    return authorizationService.permissionCheck("SKIP");
                },
            }
        })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM