我正在尝试为 child 组件创建嵌套

I am trying to created a nested for a child component

我正在尝试这样的事情:

 <Route path="/cam/cold/general" element={<General />} /> 
        <Route path='/cam/cold/general/substore' element={<jam />} >
          <Route path=':index' >
            <Route path='/order' element={<jam />} />
          </Route>
   </Route>

每个 child 都有子部分

但我一直收到此错误

router.ts:5 Uncaught Error: Absolute route path "/order" nested under path "/cam/cold/general/substore/:index" is not valid. An absolute child route path must start with the combined path of all its parent routes.

问题

Uncaught Error: Absolute route path "/order" nested under path "/cam/cold/general/substore/:index" is not valid. An absolute child route path must start with the combined path of all its parent routes.

错误提示您绝对路径 "/order" 不能嵌套在 "/cam/cold/general/substore" 下。当嵌套路由时,你应该使用相对路由。绝对路径和相对路径之间的区别在于前导 "/" 字符。绝对路径以 "/".

开头

解决方案

从嵌套的“订单”路由中删除前导 "/"

<Route path="/cam/cold/general" element={<General />} /> 
<Route path='/cam/cold/general/substore' element={<Jam />} >
  <Route path=':index'>
    <Route path='order' element={<Jam />} />
  </Route>
</Route>

如果您没有其他嵌套路由,我建议您稍微展平嵌套。

<Route path="/cam/cold/general" element={<General />} /> 
<Route path='/cam/cold/general/substore'>
  <Route index element={<Jam />} />
  <Route path=':index/order' element={<Jam />} />
</Route>