简体   繁体   English

react-router-dom,组件不渲染,但仅<app>改为显示</app>

[英]react-router-dom, component not rendering but only <App> shows instead

App.js:-应用程序.js:-

function App() {
  return (
    <BrowserRouter>
 
 <h1>App screen</h1>

    <Routes>
    <Route path="/projectDashboard"  component={ProjectScreen} ></Route>
    <Route  path="/" component={HomeScreen} ></Route>
    </Routes>


  </BrowserRouter>
  );

Output that i get:-我得到的 Output:-

I can only see the h1 tag.我只能看到 h1 标签。 The routes don't work.路线不起作用。 Whenever I enter "localhost:3000/projectDashboard" it autocorrect and sends me to "/"每当我输入“localhost:3000/projectDashboard”时,它会自动更正并将我发送到“/”

I've looked around other answers and have tried setting the exact variable as well but the issue still exists.我查看了其他答案并尝试设置确切的变量,但问题仍然存在。

In RRDv6 Route components render their components on the element prop as JSX , the component and render props no longer exist.在 RRDv6 Route组件中,将其组件在element prop 上渲染为 JSXcomponentrender props 不再存在。

<Routes>
  <Route path="/projectDashboard" element={<ProjectScreen />} />
  <Route path="/" element={<HomeScreen />} />
</Routes>

For reference Routes & Route参考路线和路线

interface RouteProps { caseSensitive?: boolean; children?: React.ReactNode; element?: React.ReactElement | null; index?: boolean; path?: string; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM