I had a question and would like to know why Angular uses # in the url?
I had a question and would like to know why Angular uses # in the url?
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
#
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'
})
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.