2015-09-22 67 views
2

我正在使用react路由器1.0.0-rc1和redux。React路由器路由但顯示錯誤消息

這是路線:

<Route path=""component={Body}> 
    <Route path="machines/:id" component={SingleMachineView}/> 
    <IndexRoute component={Dashboard}/> 
    <Route path="*" component={Dashboard}/> 
</Route> 

這是鏈接:

<Link to={`machines/${machine.machine_id}`}> 
    {machine.name} 
</Link> 

該路由器是如何開始:

class Root extends React.Component { 

    render() { 

    const history = createHashHistory(); 

    return (
     <Provider store={store}> 
     {() => <Router history={history} children={Routes}/>} 
     </Provider> 
    ); 
    } 
} 

ReactDOM.render(<Root/>, document.getElementById('app')); 

一切正常,但是當我點擊鏈接並呈現新視圖我仍然在控制檯中收到錯誤消息:

Warning: Location "machines/id2" did not match any routes

而且當我加載與路徑localhost:8080/#/machines/id2

+0

有什麼點擊鏈接時瀏覽器中的確切網址? – Clarkie

+0

'http:// localhost:8080 /#/ machines/id0?_k = cjqdch',btw我不知道'?_k = cjqdch'來自哪裏。 –

+0

@AndreasKöberle[什麼是?_k = cdjk](https://github.com/rackt/react-router/blob/master/docs/guides/basics/Histories.md#what-is-that-_kckuvup-junk-在網址) – knowbody

回答

1

的問題是爲紐帶,以開始與/

<Link to={`/machines/${machine.machine_id}`}> 
    {machine.name} 
</Link> 
0

應用在我的使用路由器或者路由器或瀏覽器中增加了一個主導/如在你的榜樣錯誤消息未出現評論。

我建議你創建一個根route/,而不是一個空字符串:

<Route path="/"component={Body}> 
    <Route path="machines/:id" component={SingleMachineView}/> 
    <IndexRoute component={Dashboard}/> 
    <Route path="*" component={Dashboard}/> 
</Route> 
+0

之前做過,但沒有幫助 –

+0

我不明白是該錯誤不匹配的網址:( – Clarkie