【发布时间】:2019-01-31 15:09:59
【问题描述】:
我正在使用 react-router-dom v4,并且很难以传递参数的方式实现路由器。
const routing = (
<Router>
<div>
<Route exact path="/" component={App} />
<Route exact path="/login" component={Login} />
<Route exact path="/app" component={Mainpage} />
<Route exact path="/app/documents" component={Documents} />
<Route exact path="/app/quizzes" component={Quizzes} />
<Route exact path="/app/new" component={Documents} />
</div>
</Router>
);
const Quizzes = ({match}) => (
<div>
<Switch>
<Route exact path="/app/quizzes" component={QuizzesInterface} />
<Route exact path="/app/quizzes/:id" component={QuizInterface} />
</Switch>
</div>
)
const QuizzesInterface = ({match}) => (
<div>
<Background />
<Interface status='quizzes' index={0}/>
</div>
)
const QuizInterface = ({match}) => {
return(
<div>
<Background />
<Interface status='quizzes' index={match.params.id}/>
</div>
)
}
当我测试 localhost:3000/app/quizzes 时,QuizzesInterface 加载正常,但是当我测试 localhost:3000/app/quizzes/1 时,例如,没有到达 QuizInterface。我做错了什么?
【问题讨论】:
-
尝试同时设置
strict -
谢谢,但还是不行。
标签: reactjs react-router react-router-v4