Why does Angularjs default to # in the URL?

Asked

Viewed 482 times

6

I have a question and I would like to know why Angular uses # at the url?

3 answers

10


To be able to have the operation of Single Page Application, because to use normal routes direct on / would need server configuration not to have refresh on the page, which is not always so simple. So by default it uses the #. But if you want you can configure to use the / through the Provider $locationProvider.html5Mode(true); in the .config() from your app and by tag <base href="/" />

Take a look at the documentation: https://docs.angularjs.org/guide/$Location

2

Hashbang, Hash, Junk, Sharp, Hashtag or simply # is who determines which page is being called, that means /#home and /index.html#homeare the same thing, since index is the main file of the application.

In other words it’s the file route.

/#home
/#sobre
/#contato

These routes are defined in your code. For example:

.when('/', {
  templateUrl : 'pages/home.html',
  controller  : 'HomeController'
})
.when('/sobre', {
  templateUrl : 'pages/sobre.html',
  controller  : 'SobreController'
})
.when('/contato', {
  templateUrl : 'pages/contato.html',
  controller  : 'ContatoController'
})
  • 1

    Who negatively could tell me why.

  • It was not I who denied, but your answer does not answer the question, simple.

0

Probably because this link is to the page itself (see RFC3986), not causing the browser to exit the current page and load a new one.

This "address", which continues to be shown in the browser, is replaced by other actions through Javascript.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.