在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML5  HTML/ 關(guān)于react-router v4 官方示例中 Link 中 to 作為對(duì)象里的

關(guān)于react-router v4 官方示例中 Link 中 to 作為對(duì)象里的 state

最近在看 react-router v4api ,在 https://reacttraining.com/react-router/web/api/Link/to-object 中看到一段代碼,

<Link to={{
  pathname: '/courses',
  search: '?sort=name',
  hash: '#the-hash',
  state: { fromDashboard: true }
}}/>

這里的state: { fromDashboard: true },我完全沒(méi)看懂,
百度了很多,沒(méi)有找到,
剛開始以為是點(diǎn)擊這個(gè) Link 時(shí)會(huì)改變 state 做了嘗試,發(fā)現(xiàn)并不是,
我還看了 Link 的源碼,也沒(méi)有發(fā)現(xiàn)什么奧秘,
所以由于好奇心的驅(qū)使,我提出了這個(gè)問(wèn)題,
想知道這個(gè)state到底是什么意思,或者是舉例有錯(cuò)誤?
求解答。

回答
編輯回答
網(wǎng)妓

state的內(nèi)容都是自定義的。你可以在Link的pathname對(duì)應(yīng)的Route的render或者children里面中的location對(duì)象拿到你自定義的state,然后做什么完全取決你

2018年4月14日 06:08
編輯回答
耍太極

傳參用的吧,去看下location

2017年12月27日 14:32
編輯回答
空白格

原生的history.pushState()方法可以傳入一個(gè) state,有些瀏覽器會(huì)把它保存起來(lái),重啟瀏覽器的時(shí)候恢復(fù) state:

state object — The state object is a JavaScript object which is associated with the new history entry created by pushState(). Whenever the user navigates to the new state, a popstate event is fired, and the state property of the event contains a copy of the history entry's state object.

The state object can be anything that can be serialized. Because Firefox saves state objects to the user's disk so they can be restored after the user restarts the browser, we impose a size limit of 640k characters on the serialized representation of a state object. If you pass a state object whose serialized representation is larger than this to pushState(), the method will throw an exception. If you need more space than this, you're encouraged to use sessionStorage and/or localStorage.

https://developer.mozilla.org/en-US/docs/Web/API/History_API

2017年8月3日 03:14