react-router-dom中文文档,API 1:BrowserRouter
BrowserRouter是一个使用THML5 history API(pushState
, replaceState
and the popstate
event)的路由<Router>
import { BrowserRouter } from 'react-router-dom' <BrowserRouter basename={optionalString} forceRefresh={optionalBool} getUserConfirmation={optionalFunc} keyLength={optionalNumber} > <App/> </BrowserRouter>
所有路由的基础地址,如果你的app分配的域名地址是带子目录的,那么就可以将basename设置为子目录
<BrowserRouter basename="/calendar" /> <Link to="/today"/> // renders <a href="/calendar/today">
getUserConfirmation: func
函数,用来确认是否跳转,默认使用window.confirm
// this is the default behavior function getConfirmation(message, callback) { const allowTransition = window.confirm(message); callback(allowTransition); } <BrowserRouter getUserConfirmation={getConfirmation} />;
forceRefresh: bool
如果设置为true,路由router将会在跳转的时候进行整个页面刷新,你可能只会用在,浏览器不支持Html5 history API的情况下
const supportsHistory = 'pushState' in window.history <BrowserRouter forceRefresh={!supportsHistory} />
keyLength: number
location.key的长度,默认为6
<BrowserRouter keyLength={12} />
children: node
要render的单个子元素 single child element
点赞(1)