2015-05-29 114 views
2

所以,我試過所有這些,但都沒有工作。同樣的錯誤的ReactJS路由可選ID的URL參數

<Route name="create-course" handler={CreateCourse} path="/course-builder/create-course/{:id}" /> 
<Route name="create-course" handler={CreateCourse} path="/course-builder/create-course/[:id]" /> 
<Route name="create-course" handler={CreateCourse} path="/course-builder/create-course{/id}" /> 

變種:

Error: Invariant Violation: Missing "id" parameter for path "/course-builder/create-course/{:id}" 

/{:?ID}一個不會引發錯誤,但URL成爲

/course-builder/create-course/%7B%7D 

請幫助!

回答

2

PARAM :id後添加?,像這樣

<Route name="create-course" handler={CreateCourse} path="/course-builder/create-course/:id?" /> 
+0

謝謝!實際工作的唯一解決方案。 – premunk

0

萬一別人絆倒在這個問題 - 因爲陣營 - 路由器的V1.0.0正確的語法是:

<Route name="create-course" handler={CreateCourse} path="/course-builder/create-course(/:id)" /> 

文檔here