2016-01-13 89 views
4

我使用的是React 0.14.0,React Router 2.0.0-rc4,browserify 11.2.0,babelify 7.2.0。反應路由器末尾的斜槓不起作用

這裏是我的路由器代碼:

render((
<Router history={browserHistory}> 
    <Route path="/" component={App}> 
    <IndexRoute component={Departments} /> 
    <Route path="goals" component={Goals} /> 
    <Route path="departments" component={Departments} > 
     <Route path="department" component={Department} /> 
    </Route> 
    </Route> 
</Router> 
), document.getElementById('react-container')) 

根/部門工作正常,但沒有根/部門/。根/部門/部門也不工作。我不知道爲什麼。

此外,它似乎與任何類型的參數:myParam無法識別。

我看不出我的代碼和文檔中提供的示例有任何區別。

另一個奇怪的是,我沒有警告:

Warning: [react-router] Location "undefined" did not match any routes 

我:

Uncaught SyntaxError: Unexpected token <  bundle.js:2 

如果我點擊bundle.js在Chrome開發人員工具鏈接我到達index.html(但bundle.js是選項卡的名稱)。

如/,出發地和目標的基本路線工作正常。

我有點卡在這個。任何意見將是有益的。

Full code available here:https://github.com/codeforabq/Open-Budget-ABQ/tree/dev
謝謝。

+0

你可以創建一個問題的一小版本小提琴? –

+0

我看了一下你的代碼並啓動了一個服務器,問題沒有反應(還)。它位於server.js和/或您的url中的路由規則中。您正在獲取語法錯誤,因爲它試圖查找/ dist/department中不存在的bundle.js。我正在玩一些東西,當我開始工作時我會發表評論。 –

+1

您在index.html中的資產URL必須是絕對的。在index.html中,將斜線添加到所有鏈接href的開頭,並添加到腳本src的開頭。 –

回答

1

'root/departments/department'將不起作用。

背後的原因是 - 部門不是'部門'的孩子。它只是'App'組件的孩子。

如果您希望允許「根/部門/部門」生成結果,那麼您必須將「部門」作爲「部門」的子項目。

對於您有如下所述,以得到路徑:

<Router history={browserHistory}> 
 
    <Route path="/" component={Departments}> 
 
    <IndexRoute component={Goals} /> 
 
     <Route path="department" component={Department} /> 
 
    </Route> 
 
    </Route> 
 
</Router>

+0

您的解決方案無法使用。 – user2705463

+0

我犯了一個小錯誤。只需將部門路徑指定爲「/部門」而不是「/」。 –

1

感謝克里斯哈迪您對絕對鏈接幫助。這是我的問題的解決方案。

用/爲絕對前綴URL後。我結束了:

Error: Invalid value for <path> attribute d="M2.4492935982947065e-15,-40A40,40 0 1,1 NaN,NaNL0,0Z" 

爲​​和http://localhost:3000/departments/department

不是非常有幫助。

我試過PHP服務器(PHP -S本地主機:3000)和我:

GET http://localhost:3000/departments/app/data/budget-first-test.tsv 404 (Not Found) 
Uncaught #<XMLHttpRequest> 

因此,在應用程序。JSX我解決這個問題行:

var dataPath = 'app/data/budget-first-test.tsv'; 

到:

var dataPath = '/app/data/budget-first-test.tsv'; 

現在,它完美的作品!參數現在也可以工作。

非常感謝!