I have the following code:
<BrowserRouter>
<IndexComponent />
</BrowserRouter>
在我内部,我有一个包含所有路由的开关。
IndexComponent.js:
<Switch >
<Route exact path="/course_info/:id" component={CourseInfoPage} />
<Route exact path="/" component={Main} />
.
.
.
</Switch>
我想要在IndexComponent中访问位置属性,以便像这样添加过渡动画:
<CSSTransition key={location.key} classNames="fade" timeout={300}>
<Switch location={location}>
<Switch >
<Route exact path="/course_info/:id" component={CourseInfoPage} />
<Route exact path="/" component={Main} />
.
.
.
</Switch>
</CSSTransition>
</TransitionGroup>
正如您所见,我需要在IndexComponent内部使用location属性。但是它并不存在。为什么呢?我应该如何添加它?