P
P
PR0metheus2016-01-09 17:10:17
Angular
PR0metheus, 2016-01-09 17:10:17

AngularJs ngRoute why don't links like "#" and "/" work?

While studying AngularJs and ngRoute, I encountered the problem of links like "#" and "/" are not
processed by ngRoute and the transition to / does not work even when specified:
$routeProvider.otherwise({ redirectTo: '/' });
Sequence of actions:

  1. open site localhost:50056/ (Debug visual studio session with IIE Express)
  2. there is a transition to the default path localhost: 50056 / # /
  3. following the links "/" and "#" are not processed and nothing is displayed in ng-view, respectively, but angularjs itself works - an empty main page is displayed, ngRoute debug shows that there is a transition from "/" to undefined

Is this normal behavior and references to / and # should be formatted as "#/" or is there something else worth reading to understand what is happening?
PS: strange but in MS Edge it works as I expect - i.e. goes to #/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-01-09
@PR0metheus

For disabled html5, the # mod is used by Angular as a delimiter for $location(). At the moment, there are already few browsers without support for the history API , so you can safely enable the html5 mod in Angular. This will make the links pretty (remove the #).
How to enable:
1. https://docs.angularjs.org/api/ng/provider/$locati... html5Mode method.
2. Set up redirects to index.html for the server. settings for different servers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question