问题
I am using react-router and in that, I am using hashRouter. Now i have to deploy my react app in sub-directory of my website. So for that, I did:
1) Added homepage parameter in package.json
file
2) Added <HashRouter basename={process.env.PUBLIC_URL}>
Now, When I access my website URL localhost/react
, I will be redirected to http://localhost/#/react/apps/
.
But I want it to be redirected to http://localhost/react/#/apps/
.
Note: I have to deploy react production build.
My production build structure:
--- static
--- asset-manifest.json
--- index.html
--- manifest.json
--- service-worker.js
Please help me, How can I achieve that? Thanks in advance for your time and answer.
回答1:
If you look at the documentation for basename, it appends the string after the hash symbol:
https://reacttraining.com/react-router/web/api/HashRouter/basename-string
If you remove basename, and your index.html is served from /reactapp - it may just work.
来源:https://stackoverflow.com/questions/55208238/set-basename-with-react-router