网站建设前言,网站建设客户需要提供什么,网站建设 百度百科,公司查名网站最近react-router的一个作者另外写了一个类react-router的组件
reach/router#xff0c;尝试后感觉太棒了。如果你的项目只是web端的话我认为可以把你的react-router换掉了。下面是我到目前看到的所有非常好的点。 小#xff0c;就4kb,压缩后比react-router小40kb左右。 更少…最近react-router的一个作者另外写了一个类react-router的组件
reach/router尝试后感觉太棒了。如果你的项目只是web端的话我认为可以把你的react-router换掉了。下面是我到目前看到的所有非常好的点。 小就4kb,压缩后比react-router小40kb左右。 更少的配置 a. react-router需要3个包(history, react-router-dom, react-router-redux)reach-router只需要一个。 b. 不需要在store配置router相关信息 c. 不需要显示的使用history // in store config file
//react-router
import { routerMiddleware } from react-router-redux;
import createHistory from history/createBrowserHistory;
const history createHistory();
const middleware routerMiddleware(history);
export { history };//reach/router, nothing 更好用 a. 当你想跳转页面时 // react-router
import { push } from react-router-redux;
import { PropTypes } from prop-types;
// use it
this.context.store.dispatch(push(/see-you));FooComponent.contextTypes {store: PropTypes.object,
};
// reach/router
import { navigate } from reach/router;
navigate(/lol);
b.当你想取url里面的参数时 // react-router
import { withRouter } from react-router-dom;
import { PropTypes } from prop-types;//use it
const { match: { params: { iAmHere } } } this.props;
FooComponent.propTypes {match: PropTypes.object,
};
export default withRouter(FooComponent);
// reach/router
const { iAmHere } this.props;基本一样的api,学习成本非常低 源码非常简洁总共就3个文件900行如果你想深入理解单页应用的路由是怎么实现的reach-router,绝对是绝佳的下手资料。
不说了去看看吧 https://github.com/reach/router
更多专业前端知识请上
【猿2048】www.mk2048.com