Angular routing

1

Good evening I am trying to use the Yeoman's Angular generator, and all good, but when I try to configure the route system with $locationProvider.hashPrefix('!') the routes fail because the route system adds an extra # in the Path.

For example without the configuration is:

  

localhost: port / # / view

but when adding the prefix it becomes:

  

localhost: port / #! / # view

and that second # is added next to the name of my view which causes that the view is not found, if I manually delete that # the view is rendered normally.

What configuration do I lack? Greetings !!!

    
asked by Dave Medina 24.11.2016 в 06:03
source

2 answers

2

I think what you need is to add:

$locationProvider.html5Mode(true);
    
answered by 25.11.2016 в 03:03
0

Make sure your links are without the # , like this: <a ng-href="/ejemplo"></a> and also have your .config implemented as follows:

ejemploApp.config(['$routeProvider', '$locationProvider', function($routeProvider,$locationProvider){
    $routeProvider
      .when('/ejemplo',{
        templateUrl: 'ejemplo.html',
        controller: 'ejemploCtrl',
        controllerAs: 'ejemplo'
      })
      .otherwise({
        redirectTo: '/error404',
      });
      $locationProvider.html5Mode(true).hashPrefix('!');
  }]);
    
answered by 25.11.2016 в 07:23