yeoman / generator-angular

Yeoman generator for AngularJS
http://yeoman.io
5.73k stars 1.44k forks source link

url contain '%2F' instead of '/' #1380

Closed barbhackk closed 7 years ago

barbhackk commented 7 years ago

Hi,

I started a new project using the generator Yeoman for Angular. When I used the command 'grunt serve' the webb app starting. When I click on the navigation (about...), I notice that the corrective page does not load and the URL contain '%2F' instead '/'. So my routing does not work.

Is it an Angular or Generator (Yo) problem? Do you have an idea ?

I'm on Macbook Pro, OS El Capitan.

Thx,

Sébastien (PNT)

blakoD-zz commented 7 years ago

Which angular version is using? if you fetch the latest Angular JS 1.6.0 version, you should downgrade angular version to 1.5.8. See #1379 .

barbhackk commented 7 years ago

I try this solution. Thanks a lot.

Sébastien

barbhackk commented 7 years ago

Hi,

Finally I did not need to downgrade Angular. I'm running on Angular 1.6.0. It is enough to replace the links href="#/blog" by "#!/blog" and it works for me.

Can customize it thanks to the method $locationProvider : https://docs.angularjs.org/api/ng/provider/$locationProvider

$locationProvider.hashPrefix(''); The default value for the prefix is '!', so #!/url

Thanks,

Sébastien

reshadf commented 7 years ago

I had the same issue which caused problems for hours yesterday. Where did you place this location provider? And are you using #!/about now or without !

barbhackk commented 7 years ago

Hi,

Now, use #!/ link instead #/ link. Work fine for me. If you want to use only #/ link, place this code $locationProvider.hashPrefix(''); like this :

angular
  .module('webApp', ['ngAnimate', 'ngAria', 'ngCookies', 'ngMessages', 'ngResource', 'ngRoute', 'ngSanitize', 'ngTouch'])
  .config(function ($routeProvider, $locationProvider) {
    $routeProvider
      .when('/blog', {
        templateUrl: 'views/blog.html',
        controller: 'BlogCtrl',
        controllerAs: 'blog'
      })
      .otherwise({
        redirectTo: '/'
      });

     $locationProvider.hashPrefix('');
  });

Sébastien

cheenbabes commented 7 years ago

^^ This solution is the simplest and works perfectly. Thanks

mikela commented 7 years ago

Hmmm, I tried to send a PR to fix this as suggested by Playntek but somehow it didn't work as expected. Advice welcome :thinking:

destpat commented 7 years ago

Look Developer Guide, Migrating from 1.5 to 1.6 for more information https://docs.angularjs.org/guide/migration#migrating-from-1-5-to-1-6

ashu17188 commented 7 years ago

I resolved by 1.Upgrading Angularjs version to 1.5.8 . 2.By adding $locationProvider.hashPrefix(''); in app.js file.

suyash0103 commented 6 years ago

Thanks a lot @sebast1. I had wasted an hour for this problem, checking my code. Thanks a lot!

lacherv commented 6 years ago

Thank you @sebast1. You are a saviour.