从AngularJS的网址删除包括hashtag(#符号) [英] Removing the hashtag from AngularJS urls (# symbol)

查看:118
本文介绍了从AngularJS的网址删除包括hashtag(#符号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从angular.js网址中删除#符号?

Is it possible to remove the # symbol from angular.js urls?

我还是希望能够使用浏览器按钮,备份等,当我改变观点和将更新使用参数的URL,但我不想#号。

I still want to be able to use the browsers back button etc when i change the view and will update the url with params, but I don't want the # symbol.

本教程routprovider声明如下

The tutorial routprovider is declared as follows

angular.module('phonecat', []).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider.
  when('/phones', {templateUrl: 'partials/phone-list.html',   controller: PhoneListCtrl}).
  when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
  otherwise({redirectTo: '/phones'});
}]);

我可以编辑本具有相同的功能,而不#?

can I edit this to have the same functionality without the #?

推荐答案

是的,你应该配置<一href=\"https://docs.angularjs.org/api/ng/provider/$locationProvider\"><$c$c>$locationProvider并设置 html5Mode 真正

angular.module('phonecat', []).
  config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {

    $routeProvider.
      when('/phones', {templateUrl: 'partials/phone-list.html',   controller: PhoneListCtrl}).
      when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
      otherwise({redirectTo: '/phones'});

    $locationProvider.html5Mode(true);

  }]);

这篇关于从AngularJS的网址删除包括hashtag(#符号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆