當我打開我的反應,終極版應用程序的主頁,我得到了錯誤window.location的是未定義
Encountered error "TypeError: Cannot read property 'search' of undefined" when prerendering App with {"location":"/","currency":"USD"}
我在下面的代碼得到錯誤
const UrlParser = {
getQueryVariable: (variable) => {
let query = window.location.search.substring(1);
let vars = query.split('&');
for (let i = 0; i < vars.length; i++) {
let pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) === variable) {
return decodeURIComponent(pair[1]);
}
}
}
}
export default UrlParser;
誰能幫我
編輯
window.location的控制檯上給人
Location {href: "http://localhost:5000/", ancestorOrigins: DOMStringList, origin: "http://localhost:5000", replace: function,
assign: function…} ancestorOrigins:DOMStringListassign:function()hash :"" host : "localhost:5000" hostname : "localhost" href : " http://localhost:5000/ " origin : " http://localhost:5000 " pathname : "/" port : "5000" protocol : "http:" reload : function reload() replace : function() search : "" toString : function toString() valueOf : function valueOf() Symbol(Symbol.toPrimitive) : undefined proto : Location
請詳細說明問題;你在哪一行遇到錯誤?哪個輸入? – pinturic
@pinturic let query = window.location.search.substring(1); – Anish
https://stackoverflow.com/a/26803253/6294260?zh_CN如果它對你有幫助,請檢查此鏈接。 –