AngularJS:如何启用$locationProvider.html5Mode与深层链接
当通过$ locationProvider.html5Mode(true)在AngularJS中启用html5Mode时,导航似乎是倾斜的,当你登陆页面更深的网站。
例如: > http://www.site.com 也许在服务器上的重写需要做不同的,或者我需要指定东西在角度,但目前我无能为力角看到的路径没有/新闻段包括。 示例main.js: // Create an application module var App = angular.module('App',[]); App.config(['$routeProvider','$locationProvider',function AppConfig($routeProvider,$locationProvider) { $routeProvider .when( '/',{ redirectTo: '/home' }) .when('/home',{ templateUrl: 'templates/home.html' }) .when('/login',{ templateUrl: 'templates/login.html' }) .when('/news',{ templateUrl: 'templates/news.html' }) .when('/news/archive',{ templateUrl: 'templates/newsarchive.html' }) // removed other routes ... *snip .otherwise({ redirectTo: '/home' } ); // enable html5Mode for pushstate ('#'-less URLs) $locationProvider.html5Mode(true); $locationProvider.hashPrefix('!'); }]); // Initialize the application App.run(['$location',function AppRun($location) { debugger; // -->> here i debug the $location object to see what angular see's as URL }]); 编辑 更新2 我检查了更改日志,但还没有发现任何有用的东西到目前为止,我想我们可以提交它作为一个错误,或不必要的行为链接到他们做了一定的更改,或只是等待,看看它是否固定后来被发布稳定版本。
发现有没有bug。
只需添加: <base href="/" /> 到您的< head /> ;. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |