我遇到了react-router 2.0.0-rc中browserHistory的問題。我試圖通過爲用戶名使用react-router參數,然後是一個名爲'edit'的嵌套靜態路由來使編輯頁面工作。當我使用react-router鏈接時,頁面按預期方式加載,但在手動輸入url或刷新後,頁面顯示空白並出現捆綁錯誤Uncaught SyntaxError: Unexpected token <
。React路由器:在動態路由刷新錯誤中嵌套靜態路由
我所有的其他路線工作正常。不幸的是,所有的文檔似乎使用靜態,其次是動態路由參數,而不是其他方式。
這裏是我的路線:
<Route path="/" component={App} onEnter={currentUserCheck}>
<IndexRoute component={HomePage} />
<Route path="/signup" component={SignupForm} />
<Route path="/login" component={LoginForm} />
<Route path="/chart" component={PollResult} />
<Route path="/:username/edit" component={EditProfile}/>
<Route path="/:username" component={ProfilePage}/>
<Route path="*" component={NoMatch}/>
</Route>
當您直接刷新或訪問它們時,其他路線是否正常工作?我認爲你需要創建一個服務器路由,爲您的反應應用程序提供服務,並知道處理任何url,而不僅僅是根url。也許檢查這個答案,看看它是否你需要:http://stackoverflow.com/questions/16579404/url-rewriting-with-expressjs。此外,您還需要確保在「服務器端」使用babel,因爲該錯誤聽起來像JSX在服務器上無法識別 –
我的所有其他路徑都正常工作。我在我的快遞服務器上抓取所有路線,將其重定向到提供我的捆綁包的索引頁面。我即將結束我的項目。這是我遇到的第一個問題。 – razzdango
感謝您的幫助。我能弄明白。 – razzdango