react-router是怎么运行的?
发布于 7 年前 作者 tomoya92 2534 次浏览 来自 分享

react-china 的体验不太好,就到这里问了 : )

react-router 网上教程多的很,但一直不知道它是怎么实现的,比如一个路由设置是下面这样的

<Router>
	<div>
		<nav>
			<Route path="/home" component={Home}/>
			<Route path="/api" component={API}/>
			<Route path="/about" component={About}/>
		</nav>
		<section>
			<Route path="/list", component={List}/>
			<Route path="/detail/:id", component={Detail}/>
		</section>
		<footer>
			balabalabala...
		</footer>
	</div>
</Router>

当我在加载了一个list页面后,循环出来列表,在列表里加上 Link

<Link to="/detail/1"/>

问题来了

当点击这个链接后,是不是页面中 section 标签内容就会被替换成 Detail 组件了?(因为是看官网里的例子写的,所以我感觉好像是替换的意思 https://reacttraining.com/react-router/)

我是这样写的,但没实现,而是在 List 组件下面出现了 Detail 组件的内容,不知道为啥,求解!!!!

回到顶部