react使用笔记

2018-03-05  本文已影响23人  hello_water
image.png
https://reactjs.org/docs/components-and-props.html#functional-and-class-components

代码分割require.ensure http://www.css88.com/doc/webpack2/guides/code-splitting-require/

react默认路由问题:https://github.com/ReactTraining/react-router/issues/4732 加exact

webpack打包之后传文件特别烦人,目录混乱

先了解react有哪些关键组件

<div>
  {props.messages.length &&
    <MessageList messages={props.messages} />
  }
</div>

要解决这个问题,请确保 && 前面的表达式始终为布尔值:

<div>
  {props.messages.length > 0 &&
    <MessageList messages={props.messages} />
  }
</div>

相反,如果你想让类似 falsetruenullundefined 出现在输出中,你必须先把它转换成字符串

react和react native分别能做什么?

react react native
html开发 app开发
以浏览器DOM作为后端 以iod或android原生控件作为后端
react直接渲染dom rn生成id,用bridge变成一个表,等待native去调用

react-router和react-router-dom的区别

react-router react-router-dom
实现路由的核心功能 基于react-router,加入了在浏览器运行环境下的一些功能,比如:Link组件,BroswerRouter、HahsRouter组件。
BroswerRouter使用pushState和popState事件构建路由。
HahsRouter使用window.location.hash和hashchange事件构建路由。
依赖于react-router,只需要显示安装react-router-dom

*react-router-reduxReact Router 和 Redux 的集成
*react-router-config 静态路由配置的小助手
*react-router-native 用于 React Native 的 React Router
*BroswerRouter使用html5 history API

Router的使用方法
Link的使用方法

HashRouter

  • basename:url的主目录,
    <HashRouter basename="/calendar"/><Link to="/today"/> // renders <a href="#/calendar/today">
  • getUserConfirmation:用于确认导航的功能。默认使用window.confirm。
    // this is the default behavior
    const getConfirmation = (message, callback) => { const allowTransition = window.confirm(message) callback(allowTransition) }
    <HashRouter getUserConfirmation={getConfirmation}/>
  • hashType:设置url中hash格式
  • slash:格式类似#/#/home
  • noslash:格式类似##home
  • hashbang:格式类似#!/#!/home
    默认是slash
  • children:node

BrowserRouter

  • basename:url的主目录,
    <HashRouter basename="/calendar"/><Link to="/today"/> // renders <a href="#/calendar/today">
  • getUserConfirmation:用于确认导航的功能。默认使用window.confirm。
    // this is the default behavior
    const getConfirmation = (message, callback) => { const allowTransition = window.confirm(message) callback(allowTransition) }
    <HashRouter getUserConfirmation={getConfirmation}/>
  • forceRefresh:设置为true时,页面切换后会全页刷新,该属性适用于那些不支持HTML5 history API的浏览器。const supportsHistory = 'pushState' in window.history; <BrowserRouter forceRefresh={!supportsHistory}/>
  • children: node

Switch使用方法

NavLink

Prompt

history

location

match

上一篇 下一篇

猜你喜欢

热点阅读