如果用户输入/ login时已经登录,我该如何重定向?

时间:2018-02-16 14:01:03

标签: angularjs redirect

我正在开发一个应用程序,但是当我从一个页面切换到另一个应用程序时,我被重定向到登录页面,如果用户已经登录,如何将重定向更改为另一个页面,因为它现在会重定向到自动登录。

app.js

'use strict';

// declare modules
angular.module('testt', []);
angular.module('Homee', []);
angular.module('Contart' , []);
angular.module('Condidature' , []);

angular.module('BasicHttpAuthExample', [
    'testt',
    'Homee',
    'Contart',
    'Condidature',
    'ngRoute',
    'ngCookies'
])

.config(['$routeProvider','$locationProvider', function ($routeProvider, $locationProvider) {

    $routeProvider
        .when('/login', {
            controller: 'LoginController',
            templateUrl: 'modules/authentication/views/login.html'
        })

        .when('/home', {
            controller: 'HomeController',
            templateUrl: 'modules/home/views/home.html'
        })
        .when('/contrat',{
            controller: 'ContartController',
            templateUrl: 'modules/contrat/views/contart.html'
        })
        .when('/candidatute',{
            controller: 'CondidatureController',
            templateUrl: 'modules/Candidature/views/candidature.html'
        })

        .otherwise({ redirectTo: '/' });
}])

.run(['$rootScope', '$location', '$cookieStore', '$http',
    function ($rootScope, $location, $cookieStore, $http) {
        // keep user logged in after page refresh
        $rootScope.globals = $cookieStore.get('globals') || {};
        if ($rootScope.globals.currentUser) {
            $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
        }

        $rootScope.$on('$locationChangeStart', function (event, next, current) {
            // redirect to login page if not logged in
            if ($location.path() !== '/login' && !$rootScope.globals.currentUser) {
                $location.path('/login');
            }
        });
    }]);

1 个答案:

答案 0 :(得分:2)

如何撤消强制登录页面重定向。这应该会给你一些技巧。

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Accordion?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane id="AnchorPane" prefHeight="486.0" prefWidth="431.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.141" fx:controller="javafxapplication115.FXMLDocumentController">
    <children>
        <Button fx:id="button" layoutX="179.0" layoutY="437.0" onAction="#handleButtonAction" text="Sum nodes" />
        <Label fx:id="label" layoutX="163.0" layoutY="37.0" minHeight="16" minWidth="69" prefHeight="17.0" prefWidth="106.0" />
      <Accordion fx:id="accordionMain" layoutX="115.0" layoutY="72.0" prefHeight="310.0" prefWidth="202.0" />
    </children>
</AnchorPane>