在我的組件之外,我需要查詢當前的活動URL。我將在此基礎上在身體上設置一些類(這在我的反應根之外)。從react-routers獲取當前頁面路徑browserHistory對象
第一次嘗試使用
//Gets an array of class names that I can add to my body tag
getClassNames(window.location.pathname);
但當陣營路由器導航似乎window.location.path 不更新。令人驚訝的是。
所以我就想,好吧,也許我可以從browserHistory
import { browserHistory } from 'react-router'
得到這個但是,唉,我看不到任何方式(沒有像樣的API文檔似乎存在從這裏閱讀當前頁面路徑對於這個對象)
任何提示?看起來像一個簡單的問題,這將是如果window.location.pathname保持與歷史對象同步。
在[email protected]應該調用'可用location.pathname' –