reactjs - HashRouter with BrowserRouter combined
问题描述
trying to figure out, how to combine these two components.
<BrowserRouter>
<Switch>
<Route exact path="/">
<HashRouter>
<Route path="/" component={Layout} />
</HashRouter>
</Route>
<Route exact path="/vizualization">
<HashRouter basename="/vizualization">
<Route path="/" component={VizualizationLayout} />
</HashRouter>
</Route>
<Route exact path="/terminal">
<HashRouter basename="/terminal">
<Route path="/" component={TerminalLayout} />
</HashRouter>
</Route>
</Switch>
</BrowserRouter>
My application is divided into three subapplications, their urls should be
http://localhost/vizualization/
and also I want to use HashRouter on these urls like
http://localhost/vizualization/#/.../...
Unfortunately, if I enter any other URL from the first one, it always redirects me to the first component called "Layout".
I have tried some combinations of basename and switches, but without luck. I would be happy if someone can help me to figure it out. Thanks!
EDIT: Also tested this
<Provider coreStore={store}>
<div>
<HashRouter basename="/">
<Route path="/" component={Layout} />
</HashRouter>
<HashRouter basename="/vizualization">
<Route path="/" component={VizualizationLayout} />
</HashRouter>
<HashRouter basename="/terminal">
<Route path="/" component={TerminalLayout} />
</HashRouter>
</div>
</Provider>
But it shows all components.
解决方案
Don't use basename="..."
thoses router are seperate from each other.
推荐阅读
- swift - 在 ipad 键盘中显示,同时从 swift 中的日期选择器编辑时间
- typescript - 我应该如何在 Typescript 中解释这种代码类型检查
- android - 当服务器从 http 切换到 https 时,Android 显示错误
- python - 如何将同义词存储为数据框中的列?
- ruby-on-rails - rspec - Big Sur 中的等 LoadError
- c - printf 自定义实现中的错误
- python - 我可以创建带有小时和秒的动态 x 轴吗?
- python - 我们如何在 Python 中使用 ntplib 库运行本地 ntp 服务器
- python - 如何告诉python从两个重复的行中取出较大的数字
- java - Android HttpURLConnection POST 不工作。使用 C#