【问题标题】:Getting the URL entered in browser before redirection in AngularJS?在 AngularJS 中重定向之前获取在浏览器中输入的 URL?
【发布时间】:2017-05-02 19:25:19
【问题描述】:

我正在尝试获取最初在浏览器中输入的 URL 的参数。但是 Angular 会自动将我“重定向”到 '/'

比如我输入这个网址:http://localhost:9080/#/test?param1=en&param2=55

但我最终得到:http://localhost:9080/#/

var config = function (AppConfig, $urlRouterProvider) {
    'ngInject';

    $httpProvider.interceptors.push(function ($q, $location) {
        return {
            'request': function (config) {
                var params = $location.search(); //here : $location is already returning the wrong URL : http://localhost:9080/#/
                return config;
            }

        }
    });

};

这是我唯一的路线:

$stateProvider.state('test', {
        url: '/',
        views: {
            'testView@' : {
                templateUrl: '/app/test/test.html',
                controller: 'test.controller',
                controllerAs: 'testVM'
            }
        }
    });

这是为什么呢?有没有办法获取原始网址?

【问题讨论】:

  • 显示你的路线定义

标签: angularjs angular-ui-router angular-http-interceptors


【解决方案1】:

用途:

document.URL;

或者

window.location.href 

【讨论】:

    猜你喜欢
    • 2014-10-20
    • 2014-07-15
    • 2015-09-20
    • 2012-10-16
    • 2013-04-27
    • 2012-09-16
    • 1970-01-01
    • 2010-10-19
    • 2012-12-01
    相关资源
    最近更新 更多