Angular UI路由器认为每个URL都不匹配并重定向

Angular UI-Router Thinks Every URL Is Unmatched And Redirects

本文关键字:URL 不匹配 重定向 UI 路由器 Angular      更新时间:2024-03-17

在我的HTML中,我有以下两个链接,但当我单击它们或尝试将它们输入浏览器时,我的新ui路由器代码会将它们重定向到我指定的otherwise url。为什么会这样?

<a href="http://localhost:3000/#!/folders/529ece6bf0686d1717000003">Folders</a>
<a href="http://localhost:3000/#!/clients">Clients</a>
//Setting up route
window.app.config(function($stateProvider, $urlRouterProvider) {
    // For any unmatched url, redirect to "/"
    $urlRouterProvider.otherwise("/asfasfsa");
    // Now set up the states
    $stateProvider
        .state('root', {
          url: "/",
          templateUrl: 'views/index.html',
          resolve: { factory: setRoot }
        })
        .state('dashboard', {
          url: "/dashboard",
          templateUrl: 'views/dashboard/dashboard.html',
          resolve: { factory: checkAuthentication }
        })
        .state('folders-show', {
          url: "/folders/:folderId'",
          templateUrl: 'views/dashboard/folders/view.html',
          resolve: { factory: checkAuthentication }
        })
        .state('clients-list', {
          url: "/clients'",
          templateUrl: 'views/clients/list.html',
          resolve: { factory: checkAuthentication }
        })
});
    // Check if user is logged in
var checkAuthentication = function ($q, $location) {
    if (window.user) {
        console.log(window.user);
        return true;
    } else {
        console.log("Not logged in...")
        var defered = $q.defer();
        defered.reject();
        $location.path("/");
        return defered.promise;
    }
};
// Set Root URLs
var setRoot = function ($q, $location) {
    if (window.user) {
        var defered = $q.defer();
        defered.reject();
        $location.path("/dashboard");
        return defered.promise;
    } else {
        return true;
    }
};

// Setting HTML5 Location Mode
window.app.config(['$locationProvider',
    function($locationProvider) {
        $locationProvider.hashPrefix("!");
    }
]);

很抱歉,folderclients URL上的简单拼写错误导致了此问题。

又被打字错误搞糊涂了!