Why does AngularJS default to # in the URL?

6

I had a question and would like to know why Angular uses # in the url?

    
asked by anonymous 21.12.2016 / 12:54

3 answers

10

In order to be able to run Single Page Application, because to use normal direct routes in / , it would be necessary to configure the server so that there is no refresh on the page, which is not always so simple. So by default it uses # . But if you want, you can configure it to use / through the provider $locationProvider.html5Mode(true); in .config() of your app and setting the <base href="/" /> tag

Take a look at the documentation: link

    
21.12.2016 / 13:04
2
Hashbang, Hash, Fix, Sustenido, HashTag or simply # is what determines which page is being called, this means that /#home and /index.html#home are the same, already that index is the main application file.

In other words, it is the file path.

/#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'
})
    
21.12.2016 / 13:03
0

Probably because this link is to the page itself (see RFC3986 ), not making the browser leave the current page and upload a new one.

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

    
21.12.2016 / 14:25