鍍金池/ 問答/HTML/ react如何在兩個頁面間傳遞參數(shù)(componentWillReceivePr

react如何在兩個頁面間傳遞參數(shù)(componentWillReceiveProps)

環(huán)境:dva.js(就是react)
我兩個頁面是不同地址的
圖片描述

有一個搜索欄,
里面有一些tag
http://localhost:8000/share 和
http://localhost:8000/searchResource
這兩個頁面的tag信息不能共享。

等于說我在主頁面http://localhost:8000/share搜索了東西之后跳轉到另一頁http://localhost:8000/searchResource,組件重新加載tag里面的信息都消失了。

然后我按后退鍵回到http://localhost:8000/share時,系統(tǒng)又會把原來老的share頁面記憶的tag信息調出來。

公司大佬跟我說用componentWillReceiveProps,我用了,沒用。我覺得那個大佬是不是沒注意我地址欄變了。
我找到了這篇文章:
http://blog.csdn.net/zrcj0706...

我的疑惑是componentWillReceiveProps是不是針對單頁面的?。康沁@個文章里說了父子頁面。

componentWillReceiveProps可以實現(xiàn)這種父子頁面的值的傳遞

render((
  <Router history={hashHistory}>
    <Route path="/" component={App}>
      {/* make them children of `App` */}
      <Route path="/repos" component={Repos}/>
      <Route path="/about" component={About}/>
    </Route>
  </Router>
), document.getElementById('app'))

核心問題:這種父子頁面是不是跟我的
http://localhost:8000/share 和
http://localhost:8000/searchResource
這種頁面不是一回事?
但是他這個父子頁面的地址欄也變了呀。和我這個地址欄變了是不是不是一回事?

回答
編輯回答
好難瘦

可以參考react-router傳參。

2017年3月21日 00:06
編輯回答
有你在

路由變化傳參有三種方式:
1.放在url里,拼成querystring,第一個頁面拼,第二個頁面取
2.放到localstorage,sessionstorage等本地存儲里
3.如果路由跳轉是用react-router-dom實現(xiàn),那么可以在跳轉的時候放到state里

<Link to={{pathname: '/searchResource', state: {你的參數(shù)對象}}}/> xxx </Link> 
2017年12月28日 12:22
編輯回答
浪婳

首先,react里沒有頁面這個概念。只有組件。你說成頁面,人家還以為頁面刷新了一次呢。

2017年10月7日 09:54