我正在升級到React v16的過程中。發佈文件指出:「除了小例外,如果你的應用程序在15.6運行沒有任何警告,它應該工作在16。」我的應用程序在15.6.2(沒有警告)上運行正常,但在16.0.0上完全沒有,在嘗試運行這些軟件包時拋出奇怪的錯誤: Uncaught TypeError: Cannot read property 'string' of undefined
當它加載其中一個軟件包文件時,以及Uncaught TypeError: Cannot read property 'string' of undefined"
加載其他。React應用程序與15.6.2正常工作,打破與16.0.0
我懷疑這個代碼是incompatiblity來源:
ReactDOM.render((
<Router>
<div>
<Route component = { Header } />
<Switch>
<Route exact path = '/' component = { Home } />
<Route exact path = '/index.html' component = { Home } />
<Route path = "/browse" component = { Browse } />
. . . . . . . etc. . . . .
</Switch>
<Route component = { Footer } />
</div>
</Router>
), document.getElementById("main"))
我渲染這一點,據我所知,任何生命週期方法之外,這個代碼是在我的WebPack配置文件中的應用程序的入口點。
我很高興追加更多的腳手架,如果它會被使用。該應用程序在15.6.2下完美運行。
'未捕獲的類型錯誤:無法讀取未定義的屬性'字符串'這是指哪個文件?你能顯示該文件,特別是它所指的行嗎? –
這是你使用的反應路由器嗎?您是否嘗試過將其升級到最新版本? (另請參閱https://stackoverflow.com/questions/46696157/react-router-cannot-read-property-string-of-undefined) – samsonthehero