React-router v6 同时显示两条路由

React-router v6 showing two routes at the same time

我这里有这段代码,我正在关注 react-router v6 示例,但在下面的代码中,routes 正在呈现两个 route<Dashboard/> 和App 启动时的 Hello 页面)。

<Routes>
        <Route path='/' element={<div><Outlet/></div>}>
          <Route index element={<div>hello</div>}/>
          <Route path="dashboard" element={<Dashboard />} />
          <Route path="login" element={<Login />} />
        </Route>
      </Routes>

当我转到 localhost/dashboard 和 localhost/login 时它工作正常,但我希望它在 'localhost/' 开始表示时呈现问候屏幕。为什么我的代码不能工作?

提前致谢。

是的,我在“<Routes/>”下留下了另一个 <Dashboard/> 组件,这就是它显示重复项的原因。