+-
在React+Electron中Router里面出错了。

在我的应用中,我有一个React Router,在React Router调用的组件中,我有另一个React Router。

App.jsx

<HashRouter> 
       <ListItemText primary={<Link style={styleRoutesMenu} to={'/relatorioView'}><p className="index__menuDescricao">Relatórios Financeiros</p></Link>}/>
       <Route path='/relatorioView' component={() => <RelatorioView tituloDaTela={setTituloDaTela}/>}/>
</HashRouter> )

和Relatorio.jsx

<HashRouter>
       <Redirect to="/diarioView" />
       <Route path='/diarioView' component={() => <DiarioView/>}/>
       <Link style={{textDecoration: "none"}} to={'/diarioView'}>
            <button>Open</button>
       </Link>
</HashRouter>

如果我在index.js中设置打开Relatorio.jsx,我的路由就能正常工作。但如果我在index.js中设置打开App.jsx,然后在那里尝试打开Relatorio.jsx,它就不能工作了。我的diarioView没有显示出来。就像我的屏幕什么都没有一样。

它的工作原理是:如果我只是打开Relatorio.jsx并尝试使用作品

它不工作:如果我试着用反应器里面的反应器打开。如果我试着用反应器里面的反应器来打开

0
投票

我能够发现.因为我的路由是嵌套的,我需要在Relatorio.jsxSo中继续URL。

<HashRouter>
       <Redirect to="**/relatorioView/**diarioView" />
       <Route path='/diarioView' component={() => <DiarioView/>}/>
       <Link style={{textDecoration: "none"}} to={'**/relatorioView/**diarioView'}>
            <button>Open</button>
       </Link>
</HashRouter>