在这里先介绍一个比较难以描述的坑
在使用react-router的时候我首先就是先在react-router的官网上去看她的官方文档,然后按照上面的教程来在自己的react工程中使用react-router,但是基本应该会遇到问题,原因就是我们在使用npm安装react-router的时候基本是4.x版本,由于版本的问题有一些我们之前在其他人的项目中看见的一些属性没法使用,其实是由于官网上的教程一些是按照版本2.x来编写的,我们需要做一些修改,使用4.x版本后我们需要的依赖是react-router-dom,而不是react-router
然后在描述一下碰到的路径匹配的问题:
ReactDom.render(
<HashRouter>
<Switch>
<Route path = '/' component={App} />
<Route path = '/PageA' component={PageA} />
<Route path = '/PageB' component={PageB} />
</Switch>
</HashRouter>, document.getElementById('root'));
实际的效果: