-1
什麼原因導致此錯誤?雙RelexDOM雙花括號錯誤
Syntax error: Unexpected token, expected ,
{ Object.keys(form_routes).map((key,index) => <Route path={key} component={{ form_routes[key] }}></Route>) }
在{{ form_routes[key] }}
充分相關的代碼:
const form_routes = {
'start': "Start",
'part1': "Part1",
'part2': "Part2",
'part3': "Part3",
'part4': "Part4",
'part5': "Part5",
'part6': "Part6"
}
ReactDOM.render(
<Provider store={store}>
<Router history={hashHistory} render={applyMiddleware(useRelativeLinks())}>
<Route path="/" component={App}>
<IndexRedirect to='/search'/>
<Route path='main' component={MainMenu}/>
<Route path='search' component={Search}/>
<Route path='form' component={Form}>
<IndexRedirect to='start'/>
{ Object.keys(form_routes).map((key,index) => <Route path={key} component={{ form_routes[key] }}></Route>) }
</Route>
</Route>
</Router>
</Provider>,
root
);
作品如果純:
<Route path='start' component={Start}></Route>
<Route path='part1' component={Part1}></Route>
<Route path='part2' component={Part2}></Route>
<Route path='part3' component={Part3}></Route>
<Route path='part4' component={Part4}></Route>
<Route path='part5' component={Part5}></Route>
<Route path='part6' component={Part6}></Route>
當它只是'component = {form_routes [key]}'它不顯示我的組件。我認爲這是因爲它等於'component =「Start」'。其他路由模式不起作用的是'component = {Start}' –
@ A.Lau:當然不會,'form_routes'包含字符串。 '{「Start」}'!='{Start}'。你必須在'form_routes'('Start',而不是'「Start」')中放入等價值,然後'{form_routes [key]}'才能工作。 –
謝謝。這對我來說有點愚蠢。花括號讓我困惑了一下。 –