search

Home  >  Q&A  >  body text

angular.js - rewrite problem when nginx deploys angularjs

Completed a project using h5 angularjs
This project uses nginx as webserver in the formal environment

The entrance to this project is shared on WeChat/Weibo
Because the project access address when sharing contains '#' (similar to: test.com/#/goods)
The position of '#' will be modified by Weibo and WeChat
As a result, the shared address cannot be accessed normally

So when sharing, you need to remove the '#' in the address
That is, the shared link is: test.com/goods

But if there is no # when entering the project, it will be abnormal
Is it possible to rewrite test.com/goods to test.com/#/goods through nginx at this time
How to write rewrite

Ask nginx experts here for advice

巴扎黑巴扎黑2776 days ago604

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-15 16:52:12

    You can consider using pushState in html5 to remove the # sign.
    Inject $locationProvider in the config method, and then set $locationProvider.html5Mode(true). See http://docs.angularjs.cn/api/ng/provider/$locationProvider
    This should be possible with nginx

    rewrite ^/(.*)$ http://test.com/#/ redirect;
    

    Use 302 jump to change the url. I haven’t tested it myself, you can try it and see

    reply
    0
  • Cancelreply