[英]React - React Router Dom, hashbang routing solution
How can I make routing in React, using react-router-dom, using hashbang?如何使用 react-router-dom 和 hashbang 在 React 中进行路由? Something like就像是
http://somesite.com/#/home http://somesite.com/#/home
http://somesite.com/#/about http://somesite.com/#/about
is fine by me.我没问题。
In Angular routing, I used { useHash: true }
in RouterModule
of angular/router
to achieve that.在 Angular 路由中,我在angular/router
的RouterModule
中使用{ useHash: true }
来实现这一点。
In Vue routing, I used history: createWebHashHistory()
in createRouter
method of vue-router
to achieve that.在 Vue 路由中,我在vue-router
的createRouter
方法中使用history: createWebHashHistory()
来实现。
Is there a way I achieve that here?我有办法在这里实现吗?
If it's not - please suggest me some other solid routing libraries for React.如果不是——请向我推荐一些其他可靠的 React 路由库。
PS If you wonder why I need it, the answer is IIS. And I don't want to go through overcomplicated procedure of getting it to work on IIS. PS 如果你想知道我为什么需要它,答案是 IIS。我不想通过过于复杂的程序让它在 IIS 上工作。
You need to use a HashRouter
: https://reactrouter.com/web/api/HashRouter您需要使用HashRouter
: https://reactrouter.com/web/api/HashRouter
For example, you can do the following:例如,您可以执行以下操作:
import { HashRouter as Router, Route, Switch } from 'react-router-dom';
const App = () => {
return (
<Router>
<Switch>
<Route exact path="/foo">
<Component1/>
</Route>
<Route exact path="/bar">
<Component2/>
</Route>
</Switch>
</Router>);
}
Use <HashRouter>
instead of one of the other routers.使用<HashRouter>
而不是其他路由器之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.