问题
I tried to add routes dynamically by using v3 but it didn't support it. React-router-v4 supports dynamic routing or not?
回答1:
It's quite unclear to me what you actually mean by dynamic routing? Are you thinking of routes provided by the API, or any sort other external source?
Sure you can, but you got to think your structure through. The easiest way to achieve that is to map them inside of your Switch Component:
<Switch>
{ routesList.map((route) => (
<Route
key={route._id}
path={route.path}
component={route.component}
{...route.props} // some custom props, maybe?
/>
)
)}
<Route path='/' component={HomePage} />
<Route path='/about' component={About} />
</Switch>
来源:https://stackoverflow.com/questions/44872941/does-react-router-v4-supports-dynamic-routing