当根 url 导航到时,以下代码 ( codesandbox ) 会产生此警告:
useRoutes()
您在“/”(下)呈现后代(或称为),<Route path="">
但父路由路径没有尾随“*”...
但是,如果我导航到“/post/blah”,则不会发出警告。
import { Routes, Route} from "react-router-dom";
const StreamPage = () => (
<>
<Routes>
<Route index element={<div /> } />
<Route path="post/:subslug/*" element={<div /> }/>
</Routes>
<Routes>
<Route index element={<div />} />
<Route path="post/:subslug/*" element={<div />} />
</Routes>
</>
)
export const App = () => (
<Routes>
<Route path="/" >
<Route path="post/*" element={<StreamPage />} />
<Route index element={<StreamPage />} />
</Route>
</Routes>
)
我知道,我可以通过合并 StreamPage 中的两个 Routes 块来修复代码,但我问这是否是预期的行为,如果是,我违反了 react-router 使用合同/API 的哪一部分?例如,我是否不允许在索引路由下没有兄弟索引路由?如果我不明白何时/为什么会产生此警告,我将来将无法避免它。
(与这个较早的问题有关)