gpt4 book ai didi

javascript - Angular UI-Router 认为每个 URL 都不匹配并重定向

转载 作者:行者123 更新时间:2023-11-30 06:27:08 26 4
gpt4 key购买 nike

在我的 HTML 中,我有以下两个链接,但是当我单击它们或尝试将它们输入浏览器时,我的新 ui-router 代码将它们重定向到我拥有的 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("!");
}
]);

最佳答案

抱歉,文件夹客户端 url 上的简单拼写错误导致了这个问题。

又被打错了!

关于javascript - Angular UI-Router 认为每个 URL 都不匹配并重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20384541/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com