我使用 Reavt V6 路线。
我正在努力让我的游戏组件中的路线工作。
访问 /test 结果是一个完全空白的页面。而它应该在游戏组件中加载犯罪模块。访问 / 渲染游戏组件,但 /test 不渲染游戏组件和其中的路由。
我如何使这个工作?
访问 url /crime 应该会导致被gamecomponent加载,并且
<Route path="/test" element={<Crime />} />
Run Code Online (Sandbox Code Playgroud)
应该加载。
应用程序.js
import React from 'react';
import logo from './logo.svg';
import './App.css';
import GameComponent from './gameComponent.jsx';
import { BrowserRouter as Router } from 'react-router-dom';
import { Routes, Route, Navigate, Outlet, Switch } from 'react-router-dom';
import PrivateRoute from './PrivateRoute';
import Login from './components/login/login.jsx';
function App() {
return (
<Router>
<Routes>
<Route path="/login" element={<Login />} />
<PrivateRoute isAuth={true} …Run Code Online (Sandbox Code Playgroud) 我试图在用户登录时重定向我的用户。但是我到目前为止发现的所有方法都不起作用。etg 我正在尝试使用 react router v6 来使用 useNavigate 功能。
但由于某种原因,我收到以下错误:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See react-invalid-hook-call for tips about how to …Run Code Online (Sandbox Code Playgroud)