如何通过<Routes />
将参数传递给我的所有路线?
这是我的Routes.js。
import React, { Component } from 'react';
import { Route, Switch, Redirect } from 'react-router-dom';
import Repos from './Repos';
import Org from './Org';
import Profile from './Profile';
class Routes extends Component {
render() {
return (
<Switch>
<Route exact path="/" render={() => (
<Redirect to='/profile' />
)} />
<Route exact path="/profile" component={Profile} />
<Route exact path="/repos" component={Repos} />
<Route exact path="/org" component={Org} />
</Switch>
);
}
}
export default Routes;
这就是我从Dashboard.js调用路由组件的方式。
import React from 'react';
import Routes from './Routes';
import Header from './Header';
const Dashboard = props => {
return (
<div>
<Header />
<Routes />
</div>
);
};
export default Dashboard;
我需要通过<Routes />
将通用道具传递到我的所有路线。我该怎么办?