Niezborala Niezborala - 5 months ago 33
Javascript Question

How to delete '#' sign in angular-ui-router URLs

I'm using angular-ui-router library and I have probelm with URLs.

I have following code:

app.js:

app.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('state', {
url: '/state',
templateUrl: 'templates/state.html',
onEnter: function () {
/*... code ...*/
}
})});


index.html:

<a href="#/state">STATE</a>


and this works, but when i delete '#' from
a
tag this dosn't work.

And here I have question, how to delete '#' sign from URL?

Answer

You need to enable HTML5Mode if you want navigation without hash tags:

app.config(["$locationProvider", function($locationProvider) {
  $locationProvider.html5Mode(true);
}]);

Beward that support for HTML5 mode depends on the browser. For those who don't support the History API, Angular will fallback to hashbang.

Comments