Removing the fragment identifier from AngularJS urls (# symbol)

后端 未结 14 2264
Happy的楠姐
Happy的楠姐 2020-11-22 00:01

Is it possible to remove the # symbol from angular.js URLs?

I still want to be able to use the browser\'s back button, etc, when I change the view and will update th

14条回答
  •  不要未来只要你来
    2020-11-22 00:46

    This answer assumes that you are using nginx as reverse proxy and you already did set $locationProvider.html5mode to true.

    ->For the people who might still be struggling with all cool stuff above.

    Surely, @maxim grach solution works fine, but for the solution for how to respond to requests that doesn't want the hashtag to be included in the first place what can be done is check if php is sending 404 and then rewrite the url. Following is the code for nginx,

    In the php location, detect 404 php error and redirect to another location,

    location ~ \.php${
      ...
      fastcgi_intercept_errors on;
      error_page 404 = /redirect/$request_uri ;
    }
    

    Then rewrite url in redirect location and proxy_pass the data, offcourse, put your website url at the place of my blog's url. (Request : Question this only after you tried it)

    location /redirect {
      rewrite ^/redirect/(.*) /$1;
      proxy_pass http://www.techromance.com;
    }
    

    And see the magic.

    And it definitely works, atleast for me.

提交回复
热议问题