如何针对给定状态强制请求服务器?

时间:2022-04-07 17:20:53

When the user navigates to /admin/logout, I want to make sure that the request is actually made, instead, I get redirected to /admin because I have a .otherwise definition:

当用户导航到/ admin / logout时,我想确保实际发出请求,而是重定向到/ admin,因为我有一个.otherwise定义:

$urlRouterProvider.otherwise( "/admin" );

When I define a state for the /admin/logout route, the state is invoked, but that still doesn't cause /admin/logout to be actually requested from the server.

当我为/ admin / logout路由定义状态时,会调用状态,但这仍然不会导致从服务器实际请求/ admin / logout。

I want to avoid creating a controller and calling /admin/logout through $http because it seems overly complicated for what I actually want to do.

我想避免创建一个控制器并通过$ http调用/ admin / logout,因为它似乎过于复杂,我实际上想做什么。

1 个解决方案

#1


0  

I ended up simply reloading the page when the state is invoked.

我最终只是在调用状态时重新加载页面。

The key for simplicity here is to simply provide window.location.reload as the controller for the state:

这里简单的关键是简单地提供window.location.reload作为状态的控制器:

function configureApplication( $stateProvider, $locationProvider, $urlRouterProvider) {
    $locationProvider.html5Mode( true );

    $urlRouterProvider.otherwise( "/admin" );

    $stateProvider
        .state( "logout", {
            url        : "/admin/logout",
            controller : window.location.reload.bind( window.location, true )
        } );
}

#1


0  

I ended up simply reloading the page when the state is invoked.

我最终只是在调用状态时重新加载页面。

The key for simplicity here is to simply provide window.location.reload as the controller for the state:

这里简单的关键是简单地提供window.location.reload作为状态的控制器:

function configureApplication( $stateProvider, $locationProvider, $urlRouterProvider) {
    $locationProvider.html5Mode( true );

    $urlRouterProvider.otherwise( "/admin" );

    $stateProvider
        .state( "logout", {
            url        : "/admin/logout",
            controller : window.location.reload.bind( window.location, true )
        } );
}