angular.js - Regarding the URL address issue of Angular single-page application
PHP中文网
PHP中文网 2017-05-15 17:08:34
0
1
596

I found that the URL addresses of many Angular single-page applications are in the following format:

http://your.domain/page/#/app/forms/validate
There is always a

number in the middle of #, which looks very unpleasant. Is there any way to change
to the following style:

http://your.domain/app/forms

Also: Can Angular's single page be replaced with pushState? Or use a plug-in called Pjax
I hope you can give me some tips, I’m a bit confused about this!

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