从AngularJS网址中删除片段标识符(#符号)

编程入门 行业动态 更新时间:2024-10-22 21:40:29
本文介绍了从AngularJS网址中删除片段标识符(#符号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以从angular.js URL中删除#符号?

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

当我更改视图并使用参数更新URL时,我仍然希望能够使用浏览器的后退按钮等,但是我不希望使用#符号.

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

教程routeProvider声明如下:

The tutorial routeProvider 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 #?

推荐答案

是的,您应该配置 $locationProvider 并将 html5Mode 设置为true:

Yes, you should configure $locationProvider and set html5Mode to true:

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网址中删除片段标识符(#符号)

本文发布于:2023-10-12 23:29:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486195.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识符   片段   符号   网址   AngularJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!