我在写个人博客的时候,遇到的问题是有关React-router的问题,这个问题困扰了我很久的,百度也找了很久最终还是以失败而告终,没办法去看了阮一峰写的学习讲解,链接地址如下:http://www.ruanyifeng.com/blog/2016/05/react_router.html,阮一峰老师确实写的不错的,看完之后自己又分析了一下自己写代码;最终找出了原因React-router4.0版本和React-router2.0版本不兼容的,所以在4.0批量加路由的时候我们应该加上:
1.导入头文件
import { BrowserRouter as Router, Link } from 'react-router-dom';
2.路由代码如下:
render() {
return (
<Router>
<div className = "home-header">
<div className = "home-header-title"><Link to = "/">王宁的个人主页</Link></div>
<div className = "home-header-subtitle">WangNing PersionalBlog</div>
<div className = "home-header-nav">
<div className = "home-header-nav-item"><Link to = "/home">Home</Link></div>
<div className = "home-header-nav-item"><Link to = "/blog">Blog</Link></div>
<div className = "home-header-nav-item"><Link to = "/demo">Demo</Link></div>
<div className = "home-header-nav-item"><Link to = "/about">About Me</Link></div>
</div>
</div>
</Router>
);
}
}```
如此写才解决我的大麻烦。搞了好久不如去看一下大佬们的讲解。技术太差没办法啊。
网友评论