当前位置: 代码迷 >> 综合 >> 关于react-router-dom 6.0.1的基础写法 解决Error: A <Route> is only ever to be used as the child of <Routes>
  详细解决方案

关于react-router-dom 6.0.1的基础写法 解决Error: A <Route> is only ever to be used as the child of <Routes>

热度:18   发布时间:2023-12-25 15:46:12.0

关于react-router-dom 6.0.1的基础写法 解决Error: A <Route> is only ever to be used as the child of <Routes>

import React from 'react';
import {
     BrowserRouter as Router, Route, Link, Routes } from 'react-router-dom';const First = () => <div>页面一的内容</div>;export default function RouterHandler() {
    return (<Router><div><h1>路由基础</h1><Link to='/first'>页面一</Link>{
    /*解决 A <Route> is only ever to be used as the child of <Routes>*/}<Routes><Route path='/first' element={
    <First />} /></Routes></div></Router>);
}
  相关解决方案