angularJS 路由不能正常工作 URL中出现#!

来源:互联网 发布:机加工成本计算软件 编辑:程序博客网 时间:2024/06/08 02:16
原文来自 http://blog.csdn.net/github_38469481/article/details/70598066
使用ng-route大于1.6.0的版本时,地址中的 "/" 会自动被解析 而且还会在URL地址中加入#! 导致路由不能正常的工作 

如图所示

  

解决此问题的方法有两种 :

1、如果坚持使用当前版本的angular则在配置路由时添加如下代码

  1. $locationProvider.hashPrefix('');
代码如下所示
  1. var myApp= angular.module('myApp',['ngRoute']);
  2. myApp.config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider){
  3. //这是因为Angular 1.6 版本更新后 对路由做的处理,这样才可以和以前版本一样正常使用
  4. $locationProvider.hashPrefix('');
  5. $routeProvider
  6. .when('/RuKu',{
  7. controller:'Acontroller',
  8. templateUrl:"./viewes/viw1.html",
  9. })
  10. .when('/OrderDetial',{
  11. controller:'Bcontroller',
  12. templateUrl:"./viewes/viw2.html"
  13. })
  14. .otherwise('/RuKu');
  15. }]);
效果如下所示 路由可以正常工作


2、使用比1.6.0的低的版本。
原创粉丝点击