generator-angular icon indicating copy to clipboard operation
generator-angular copied to clipboard

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

Open barbhackk opened this issue 9 years ago • 11 comments

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)

barbhackk avatar Dec 12 '16 13:12 barbhackk

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 .

blakoD-zz avatar Dec 12 '16 17:12 blakoD-zz

I try this solution. Thanks a lot.

Sébastien

barbhackk avatar Dec 13 '16 06:12 barbhackk

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

barbhackk avatar Dec 13 '16 11:12 barbhackk

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 !

reshadf avatar Dec 13 '16 14:12 reshadf

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

barbhackk avatar Dec 13 '16 17:12 barbhackk

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

cheenbabes avatar Dec 16 '16 18:12 cheenbabes

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:

mikela avatar Dec 18 '16 01:12 mikela

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

destpat avatar Mar 14 '17 10:03 destpat

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

ashu17188 avatar Mar 17 '17 09:03 ashu17188

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

suyash0103 avatar Dec 15 '17 18:12 suyash0103

Thank you @sebast1. You are a saviour.

lacherv avatar Feb 27 '18 05:02 lacherv