Home  >  Q&A  >  body text

angular.js - 关于Angular单页应用的URL地址问题

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

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

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

http://your.domain/app/forms

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

PHP中文网PHP中文网2689 days ago525

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-15 17:10:34

    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

    reply
    0
  • Cancelreply