[英]React-router-dom link page not working correctly
I am using react-router-dom library for work with routers, but when I want to link to another page it dosen't change the page and added new page right after previous change like bellow image. 我正在使用react-router-dom库与路由器一起工作,但是当我想链接到另一个页面时,它不会改变页面并在之前的更改之后添加新页面,如下图所示。 How can I fix this? 我怎样才能解决这个问题? mentioned image 提到的形象
Main.js: Main.js:
const routes = (
<HashRouter>
<div>
<Route path="/" component={App} />
<Route path="/about" component={About} />
</div>
</HashRouter>
);
ReactDom.render(routes , document.getElementById('app'));
Link page: 链接页面:
<Menu.Item key="morepage:about"><Link to="/about">About Page</Link></Menu.Item>
You need to make use of <Switch>
and put path="/"
on the last 您需要使用<Switch>
并将path="/"
放在最后
import {HashRouter, Route, Switch} from 'react-router-dom';
<HashRouter>
<div>
<Switch>
<Route path="/about" component={About} />
<Route path="/" component={App} />
</Switch>
</div>
</HashRouter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.