angular.js - rewrite problem when nginx deploys angularjs
巴扎黑
巴扎黑 2017-05-15 16:50:12
0
1
621

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

巴扎黑
巴扎黑

reply all(1)
我想大声告诉你

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template