【发布时间】:2022-01-06 05:15:05
【问题描述】:
这是我的 app.js 代码 我已经安装了 react-router dom 版本 6 并使用了路由而不是 swicthes 我仍然收到此错误。我还尝试将 react.fragment 放在路由下,但错误仍然没有消失。请帮忙,因为我是新来的反应
import './App.css';
import React, { Component,} from 'react'
import Navbar from './Components/Navbar';
import News from './Components/News';
import {
BrowserRouter as Router,
Routes,
Route
} from "react-router-dom";
export default class App extends Component {
render() {
return (
<div>
<Router>
<Navbar />
<Routes>
<Route exact path="/business"> <News key="business" country="in" category="business" /></Route>
<Route exact path="/entertainment"><News key="entertainment" country="in" category="entertainment" /></Route>
<Route exact path="/general"><News key="general" country="in" category="general" /></Route>
<Route exact path="/health"><News key="health" country="in" category="health" /></Route>
<Route exact path="/science"><News key="science" country="in" category="science" /></Route>
<Route exact path="/sports"> <News key="sports" country="in" category="sports" /></Route>
<Route exact path="/technology"><News key="technology" country="in" category="technology" /></Route>
</Routes>
</Router>
</div>
)
}
}
【问题讨论】:
-
stackoverflow.com/a/70108430/269694 这似乎是您问题的解决方案。这里也是他们的入门教程的链接:github.com/remix-run/react-router/blob/main/docs/…
标签: reactjs react-router