2015-11-02 59 views
1

如果从地址url中删除#,我试图在我的路由器中使用$ location提供程序。在第一次加载时将根改为另一个url的作品。但是当我重新加载新的一页它的自我,我得到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); 

    }]); 

这是我使用重定向控制器

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") 
    }; 

}]); 

请帮助我在这个问题上!

+0

从粗略地看一眼,都没有问题。你可以创建一个plunkr或类似的复制你的问题? –

回答

0

你应该在你的服务器端(后端)处理这个 其实请求http://server.net/setting这样会带你到网络服务器和你的Web服务器不能正常回复您,

在appache我用PHP索引页

是这样的:

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> 

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

+0

可能很适合查看UI路由器的文档以解决此问题。 https://github.com/angular-ui/ui-router 使用$ locationProvider.html5Mode(true); – Ebrahim

+0

这里的问题是,我使用phonegap服务器,我没有访问服务器端 –

+0

萨拉姆,不幸的是你需要服务器端设置兄弟。 – Ebrahim

相关问题