Reactjs React JS:将值从路由传递到组件
我有这些路线Reactjs React JS:将值从路由传递到组件,reactjs,Reactjs,我有这些路线 <Router> <Switch> <Route path="/" exact component={Home} /> <Route path="/reports" exact component={ReportPage} /> <Route path="/reports/browse" exact component={ActiveRepo
<Router>
<Switch>
<Route path="/" exact component={Home} />
<Route path="/reports" exact component={ReportPage} />
<Route path="/reports/browse" exact component={ActiveReportsPage} />
<Route path="/signin" exact component={SigninPage} />
</Switch>
</Router>;
您可以通过路由器传递
params
,路由器可通过match
道具访问:
<Router>
<Switch>
<Route path="/" exact component={Home} />
<Route path="/reports/:parameter" exact component={ReportPage} />
<Route path="/reports/browse" exact component={ActiveReportsPage} />
<Route path="/signin" exact component={SigninPage} />
</Switch>
</Router>;
;
然后可以在ReportsPage组件中访问:
this.props.match.params.params.parameter
您还可以useparms
<Router>
<Switch>
<Route path="/" exact component={Home} />
<Route path="/reports/:parameter" exact component={ReportPage} />
<Route path="/reports/browse" exact component={ActiveReportsPage} />
<Route path="/signin" exact component={SigninPage} />
</Switch>
</Router>
在组件ReportPage
中使用useparms
让{parameter}=useParams()
你的路线将如何获得项目编号你能显示该函数或映射函数吗?工作起来就像一个奇迹:)_
<Router>
<Switch>
<Route path="/" exact component={Home} />
<Route path="/reports/:parameter" exact component={ReportPage} />
<Route path="/reports/browse" exact component={ActiveReportsPage} />
<Route path="/signin" exact component={SigninPage} />
</Switch>
</Router>