Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

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

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.

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 #?

1 Answer

0 votes
by (106k points)
edited by

Before removing the fragment identifier from AngularJS urls be sure to check browser support for the html5 history API see the code below:-

if(window.history && window.history.pushState){ 

$locationProvider.html5Mode(true); 

}

Are you willing to pursue a career in Angular, here's an opportunity for you; Angular Training provided by intellipaat!

Related questions

+2 votes
1 answer
+1 vote
1 answer
+2 votes
1 answer

Browse Categories

...