小编Hai*_*373的帖子

在 React Router v6 中嵌套路由时将 props 传递给 <Outlet />?

当我嵌套路由时,如何传递props给组件?<Outlet />

// Parent Comp 
{
  const [format, setFormat] = useState('rgb');
  const color = [hex, rgb, rgba]
  
  // ...

  return (
    <PaletteNavBar changeFormat={setFormat}/>

      {colorId ? <ColorBoxes /> : <Outlet color={color[format]} />}

      // setFormat(hex) is called down here
    <PaletteFooter />;
  )
}
Run Code Online (Sandbox Code Playgroud)

我不想通过 URL 参数传递它们。

reactjs react-router react-router-dom

7
推荐指数
1
解决办法
8699
查看次数

标签 统计

react-router ×1

react-router-dom ×1

reactjs ×1