react-router v4 API 翻译(二)

HashRouter

它是一种Router,其使用了URL的hash值来使得页面和浏览器的history保持一致。另外Hash history 不支持 location.key 和 location.state。另外由于该技术只是用来支持旧版浏览器,因此更推荐大家使用 BrowserRouter。
参数:

  • basename:string
    为所有位置添加一个基准URL,如果该应用被部署在服务器上的子目录上,那么就应当将basename的值设置为这服务器的子目录。正确的basename,反斜杠\应当在前面而不是在后面。
    <HashRouter basename="/calendar"/>
    <Link to="/today"/> // renders <a href="#/calendar/today">
    
    • getUserConfirmation: func
      其值是一个函数,该函数被用来确认是否跳转,默认使用window.confirm
      (Window.confirm()方法显示一个对话框,对话框里面的内容是message参数和确认、取消两个按钮。)
    //这是默认行为
    const getConfirmation = (message, callback) => {
      const allowTransition = window.confirm(message)
      callback(allowTransition)
    }
    <HashRouter getUserConfirmation={getConfirmation}/>
    
  • hashType: string
    用于window.location.hash的编码类型。 可用值包括:
    • “slash” - 创建像#/和#/ sunshine / lollipops这样的哈希
    • “noslash” - 创建像#和#sunshine / lollipops这样的哈希
    • “hashbang” - 创建“ajax crawlable”哈希(已经被谷歌弃用),如#!/和#!/ sunshine / lollipops
  • children: node
    渲染唯一子元素。作为一个 Reac t组件,天生自带 children 属性。也就是render()的内容,其只能是一个子节点,当然了,里面可以嵌套多个

猜你喜欢

转载自blog.csdn.net/XUAN_1995/article/details/84337230