angular.js - 关于Angular单页应用的URL地址问题
PHP中文网
PHP中文网 2017-05-15 17:08:34
0
1
523

我发现很多Angular的单页应用的URL地址都是如下的格式:

http://your.domain/page/#/app/forms/validate

中间都是有一个#号,看着很不爽,
能不能通过什么方式改变成如下的样式:

http://your.domain/app/forms

另外:Angular的单页可以用pushState替换吗?或者用一个叫Pjax的插件
希望大家给点提示,这一块有点懵!

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
phpcn_u1582

If it is angular 1.x, you can add a sentence at the end of the route $locationProvider.html5Mode(true);

app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
 $routeProvider
 .when('/article', {
   templateUrl: '/article.html',
   controller: 'ArticleController'
 }).otherwise({
   redirectTo: '/index'
 });
 $locationProvider.html5Mode(true);
}])

This routing scheme defaults to the hash method starting with #. If you do not consider lower version browsers, you can directly call $locationProvider.html5Mode(true) to use the H5 scheme instead of the hash scheme.

If you are interested, please read my article directly. There is an article explaining the front-end routing mechanism in detail

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!