在页面重载使用$ locationProvider不起作用 [英] using $locationProvider in page reload doesn't work

查看:170
本文介绍了在页面重载使用$ locationProvider不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从URL地址#消除的情况下,我试图用$位置提供在我的路由器。在第一负载改变根到另一个URL的作品。但是当我重新加载新的一页它的自我,我得到拿不到/功能主义

in case of eliminating # from address url , I tried to use $location provider in my router. at the first load changing root to another url works. but when I reload the new page it self i get Cannot GET /functionalists

这是我的配置:

app.config(['$routeProvider','$locationProvider' ,
    function ($routeProvider , $locationProvider ) {
        $routeProvider.
            when('/functionalists',
            {
                templateUrl: '/public/app/views/functionalities/functionalities.html',
                controller: 'FuntionalitiesController'


            })
            .when('/setting',
            {
                templateUrl: '/public/app/views/setting/setting.html',
                controller: 'SettingController'
            })
            .when('/guide',
            {
                templateUrl: '/public/app/views/guide/guide.html',
                controller: 'GuideController'
            })
            .when('/contact',
            {
                templateUrl: '/public/app/views/contactus/contactus.html',
                controller: ''
            })
            .when('/token',{

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

        $locationProvider.html5Mode(true);

    }]);

这是我使用重定向控制器

this is the controller which I use for redirect

app.controller('MainViewController', ['$scope', '$location', 'MainViewFactory', function ($scope, $location, MainViewFactory) {

    $scope.functions = function () {
        $location.path("/functionalists")
    };
    $scope.setting = function () {
        $location.path("/setting")
    };
    $scope.guide = function () {
        $location.path("/guide")
    };
    $scope.contactUs = function () {
        $location.path("/contact")
    };

}]);

请帮我在这问题!

推荐答案

您应该在你的服务器端处理这个(后端)
其实请求 http://server.net/setting 这种方式会带你到网络服务器和你的网络服务器不正确回答你,

You should handle this at your server side (back end) Actually the request http://server.net/setting this way will take you to the webserver and your webserver does not reply you properly,

在appache和PHP索引页我用的是这样的:

in appache and php index page I use something like this:

Header add Access-Control-Allow-Origin "http://localhost:3000"
Header add Access-Control-Allow-Credentials "true"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "GET, POST"
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]


<FilesMatch "\.php$">
Order Allow,Deny
Deny from all
</FilesMatch>
<FilesMatch "index[0-9]?\.php$">
Order Allow,Deny
Allow from all
</FilesMatch>

如果你没有在你的后端访问,你应该使用#标签,可惜

If you do not have access on your backend, you should use the hashtags, unfortunately

这篇关于在页面重载使用$ locationProvider不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆