我第一次尝试React-Router,并尝试编写一些代码,但链接似乎不起作用。这些是我的链接。起初,当我将链接放入应用程序组件中时,链接起作用了。然后我尝试将导航放入它自己的组件中,然后链接不起作用。感谢您的帮助!import React from "react";import About from "./About";import Home from "./Home";import Navigation from "./Navigation";import { BrowserRouter as Router, Switch, Route } from "react-router-dom";export default function App() { return ( <Router> <div> <Navigation /> <Switch> <Route path="/about"> <About /> </Route> <Route path="/" exact> <Home /> </Route> </Switch> </div> </Router> );}import React from "react";import { BrowserRouter as Link } from "react-router-dom";export default function Navigation() { return ( <nav> <ul> <li> <Link to="/">Home</Link> </li> <li> <Link to="/about">About</Link> </li> </ul> </nav> );}
1 回答
慕容3067478
TA贡献1773条经验 获得超3个赞
您正在导入import { BrowserRouter as Link } from "react-router-dom";
它应该是import { Link } from "react-router-dom";
添加回答
举报
0/150
提交
取消