简体   繁体   中英

React-router doesn't handle hash from my path

I have my react-router setup like this:

<Router history={browserHistory}>
     <Route path="/" component={App}>
     {/* other routes */}
</Router>

I'm using browserHistory from react-router.

My application is on Amazon S3 bucket and when I make initial request everything works fine on Chrome and Firefox but on Safari, Edge and IE it doesn't work.

I see hash added in the path which is added on the server.

So basically if I enter:

https://example/foo

It becomes:

https://example/#/foo

My react-router doesn't know how to route it properly since no route with hash is defined in my routes. Am I doing something wrong? Thanks in advance.

Consider using hashHistory instead of browserHistory which is also available in React router via import { hashHistory } from 'react-router' . ( eg. <Router history={hashHistory}> instead of <Router history={browserHistory}> )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM