gpt4 book ai didi

javascript - UI-路由器。如何导航到项目中我不想包含为状态的页面?

转载 作者:行者123 更新时间:2023-11-27 23:49:37 24 4
gpt4 key购买 nike

我仍在学习 Angular 和 UI-Router...因为我几乎走了 UI-Router 路线,因为每个人都告诉我这是要走的路..

我最初将登录页面作为所有州的一部分......但决定最好将其保留为单独的独立页面

但我不知道如何重定向到登录页面...

app.config(['$urlRouterProvider', '$stateProvider', function ($urlRouterProvider, $stateProvider) {
$urlRouterProvider
.otherwise('');

//what i used to have, will remove this
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'Account/Login',
})..etc

现在如果我想重定向到实际的 URL..我该怎么做?

我已经尝试过:

$location.url('/Account/Login');
$location.path('/Account/Login');

但它们似乎只是附加到 URL 上。如何使用 UI-Router 并转到项目中非状态的页面?

最佳答案

您始终可以访问任何 native JavaScript 窗口方法。 Angular 提供了对它的可注入(inject)引用 $window

$window.location = '/non-angular-url';
// OR
window.location = '/non-angular-url';

$window: A reference to the browser's window object. While window is globally available in JavaScript, it causes testability problems, because it is a global variable. In angular we always refer to it through the $window service, so it may be overridden, removed or mocked for testing.

关于javascript - UI-路由器。如何导航到项目中我不想包含为状态的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32833286/

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