Angular UI-Router认为每个URL都是无与伦比的,并且重定向

时间:2013-12-04 19:47:42

标签: javascript angularjs angular-ui-router

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

<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("!");
    }
]);

1 个答案:

答案 0 :(得分:0)

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

再次被错别字挫败!