I have an application with this config for history:
import { createHashHistory } from 'history';
import { ConnectedRouter } from 'connected-react-router';
const history = createHashHistory({
hashType: 'slash',
});
...
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
But all my routes get appended by /#
ex: localhost:8080/
bees: localhost:8080/#/
I already tried to update my packages as this question say but it didn't work.
The only thing that worked was change createHashHistory
to createBrowserHistory
, but I'm not sure what's the difference between them, and why createHashHistory
is appending the /#
I have an application with this config for history:
import { createHashHistory } from 'history';
import { ConnectedRouter } from 'connected-react-router';
const history = createHashHistory({
hashType: 'slash',
});
...
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
But all my routes get appended by /#
ex: localhost:8080/
bees: localhost:8080/#/
I already tried to update my packages as this question say but it didn't work.
The only thing that worked was change createHashHistory
to createBrowserHistory
, but I'm not sure what's the difference between them, and why createHashHistory
is appending the /#
-
1
Hash routing in general is UI routing that contains a
/#/
. It utilizes thehashchange
andwindow.location.hash
API to simulate routing. Alternately, UI routing uses thehistory
API to update the URL and store previous states in browser memory. – Austin Ezell Commented May 28, 2020 at 20:54
1 Answer
Reset to default 4With hashHistory, it produces url like http://yourwebsite/#page/xxx
With browserHistory, it produces url like http://yourwebsite/page/xxx
Which one to use? In real-world products, browserHistory is mostly used. A rule of thumb is "if you are using a dynamic server that can handle dynamic URLs then you need to use the BrowserRouter ponent but if you are using a server that only serves static files then a HashRouter ponent is what to be used in this case."
In your code, hashType: 'slash' is just the default value.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745622677a4636617.html
评论列表(0条)