Url loads characters ! #%2F and does not load the correct view in Angular

Asked

Viewed 161 times

0

I am at my root index.html and loads normal, but when I type the # more the / and a view for example the view tests the url: index.html#! #%2Fview-test. I would like to know the pq!

Follow the code of the route:

angular.module('teste').config(['$routeProvider', '$locationProvider'], 
    function($routeProvider, $locationProvider){
       $locationProvider.html5Mode(true);
       $routeProvider

       .when('/', {
         templateUrl: 'index.html',
         controller: 'testeCtrl'
       })
       .when('/teste', {
         templateUrl: 'view/teste.html',
         controller: 'testeCtrl'
     });                                                                  
 });

1 answer

1


Leandro, when you see the html5Mode arrow, you disable the use of the #, or what we call the friendly url.

To continue using the #, you have to remove the line $locationProvider.html5Mode(true);. And to use the user-friendly url, you need to set the head of index.html to <base href="/"> and set the $locationProvider.html5Mode(true)

Hugs!

  • now you are giving error in the console so: Error: $injector:modulerr

  • 1

    may be that you forgot to put the reference of some file or module not ? as for example ngRoute ....

  • 1

    @stringname this same that occurred!

Browser other questions tagged

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