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

鍍金池/ 問(wèn)答/HTML5  HTML/ React 使用 state傳值, 頁(yè)面刷新后state為空了

React 使用 state傳值, 頁(yè)面刷新后state為空了

請(qǐng)問(wèn)下,從A頁(yè)面跳轉(zhuǎn)到B頁(yè)面,用state傳值,在B頁(yè)面刷新后 state就為空了,怎么解決?

A頁(yè)面 傳值代碼

    render: (text, record, index) => {
      const path = {
        pathname:'/goods-details',
        state: {
          outerItemId: record.outerItemId,
        },
      }
      return <Link to={path}>{text}</Link>;
    },

回答
編輯回答
吢涼

to: object
An object that can have any of the following properties:
pathname: A string representing the path to link to.
search: A string represenation of query parameters.
hash: A hash to put in the URL, e.g. #a-hash.
state: State to persist to the location.
https://reacttraining.com/rea...

2018年8月14日 19:26
編輯回答
涼薄

改成browserhistory,刷新頁(yè)面,參數(shù)不會(huì)刷新

2017年1月11日 11:16
編輯回答
懷中人

這肯定沒(méi)了啊,刷新了連redux都沒(méi)了,更別說(shuō)state了
解決方法1:把數(shù)據(jù)放localStorage里,在這個(gè)組件加載前,先從rouer的state里取,沒(méi)有就從localStorage取,再?zèng)]有就真沒(méi)有了。能解決,但是不現(xiàn)實(shí)。
解決方法2:把這個(gè)id放在url的search部分,這樣頁(yè)面刷新還在,然后在這個(gè)組件加載前,先從rouer的state里取,沒(méi)有就用這個(gè)id從server端取。

2018年1月17日 12:03