用react-router写了个单页面应用,使用 ‘html-webpack-plugin’ 自定义添加html文件。
现在有个需求,是在切换路由到不同的页面时,要修改 head中的标签的值。
请问,有什么好的方法或思路吗?
用react-router写了个单页面应用,使用 ‘html-webpack-plugin’ 自定义添加html文件。
现在有个需求,是在切换路由到不同的页面时,要修改 head中的标签的值。
请问,有什么好的方法或思路吗?
我是这么来的:
<Route path="/path" component={ ComponentPath } onEnter={ ComponentPath.onEnter } ></Route>
在组件ComponentPath定义一个onEnter的静态方法。然后通过Route
的onEnter的prop传入
在ComponentPath.onEnter
静态方法里面修改title,不知道有没有更好的方法?欢迎交流!