每当用户打开“localhost:3000”时,我必须将用户重定向到“localhost:3000/home/dashboard”

问题描述 投票:0回答:1

每当用户打开

localhost:3000
时,我都必须将用户重定向到
localhost:3000/home/dashboard
。如何让路由器在 React 应用程序中执行此操作?

我尝试过,但没有得到我想要的结果。

<Router>
  <div>
    <Routes>
      <Route path="/*" element={<AdminSignIn />} />
      <Route
        path="/assignment/:companyId/:frameworkId"
        element={<UserSignIn />}
      />
      <Route path="/company/:companyName" element={<CompanyReview />} />
    </Routes>
  </div>
</Router>
javascript reactjs react-router
1个回答
0
投票
import {BrowserRouter as Router,
  Routes, Route, Navigate} from 'react-router-dom'

<Router>
  <div>
    <Routes>
      <Route path="/" element={<Navigate replace to="/home/dashboard" />} />
      <Route path='/home/dashboard' element={<Dashboard />}></Route>
      <Route path="/*" element={<AdminSignIn />} />
      <Route
        path="/assignment/:companyId/:frameworkId"
        element={<UserSignIn />}
      />
      <Route path="/company/:companyName" element={<CompanyReview />} />
    </Routes>
  </div>
</Router>
© www.soinside.com 2019 - 2024. All rights reserved.