简体   繁体   English

在window.location.href之前/期间进行烘烤

[英]Toast before/during window.location.href

I would like to show a toast before redirect to login. 我想在重定向到登录之前显示祝酒词。 In my case I have this code in my interceptor: 就我而言,我的拦截器中包含以下代码:

'use strict';
 angular.module('frontEndApp')
 .config(['$provide', '$httpProvider', function ($provide, $httpProvider, 
 $translate, toastr, CONST) {
    $provide.factory('unauthorisedInterceptor', ['$q', function ($q) {
        return {
            'responseError': function (rejection) {
                if (rejection.status === (401)) {
                    window.location.href = '/#/login';
                }
                if (rejection.status === (405)) {
                    window.location.href = '/#/login';
                    $translate('createsuccess')
                        .then(function (translatedMessage) {
                            toastr.success(translatedMessage, {
                                'timeOut': CONST.TOAST.timeOut,
                                'extendedTImeout': CONST.TOAST.extendedTImeout,
                                'progressBar': CONST.TOAST.progressBar,
                                'closeButton': CONST.TOAST.closeButton,
                                'showMethod': CONST.TOAST.showMethod,
                                'hideMethod': CONST.TOAST.slideUp
                            });
                        });
                }
                return $q.reject(rejection);
            }

        };
    }]);
    $httpProvider.interceptors.push('unauthorisedInterceptor');
}]);

I would like to show to the user why they are redirecitng to the login page... 我想向用户展示为什么他们重​​新使用登录页面...

Can you help me, The toastr doesn't appear. 您能帮我吗,吐司没有出现。

Use the location service to re-route the request as I assume you're using ngRoute. 假设您使用的是ngRoute,请使用位置服务重新路由请求。 Using the window.location.href you are causing the browser to do a get request and reload the entire page, not utilizing angular's routing. 使用window.location.href会导致浏览器执行get请求并重新加载整个页面,而不是利用angular的路由。

'use strict';
 angular.module('frontEndApp')
 .config(['$provide', '$httpProvider', function ($provide, $httpProvider, 
 $translate, toastr, CONST) {
    $provide.factory('unauthorisedInterceptor', ['$q', '$location', function ($q, $location) {
        return {
            'responseError': function (rejection) {
                if (rejection.status === (401)) {
                    $location.url('/login');
                }
                if (rejection.status === (405)) {
                    $location.url('/login');
                    $translate('createsuccess')
                        .then(function (translatedMessage) {
                            toastr.success(translatedMessage, {
                                'timeOut': CONST.TOAST.timeOut,
                                'extendedTImeout': CONST.TOAST.extendedTImeout,
                                'progressBar': CONST.TOAST.progressBar,
                                'closeButton': CONST.TOAST.closeButton,
                                'showMethod': CONST.TOAST.showMethod,
                                'hideMethod': CONST.TOAST.slideUp
                            });
                        });
                }
                return $q.reject(rejection);
            }

        };
    }]);
    $httpProvider.interceptors.push('unauthorisedInterceptor');
}]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM