Now I am define route "react-router-dom": "^5.1.1", like this:
const Channel = loadable(() => import(/* webpackChunkName: 'about' */ '@/views/App/Cruise/Channel'))
const routes = [
{ path: '/index', exact: true, name: 'Index', component: Channel, auth: [1] }
]
for the old way, I am pass props into component like this way:
class App extends React.Component {
render() {
return (<Router>
<Switch>
<Route path='/login' render={(props) => <Login user={this.props.user} />}/>
</Switch>
</Router>)
}
}
how to pass props into component Channel when define route as an array? I have tried this way:
{
path: '/app/cruise/channel',
exact: false,
name: 'Channel',
render: (props) => (<Channel {...props} channel={this.props.channel}/>)
},
but it could not work. Now I am passed the props like this in the routes outer component:
<Content className='content'>
<Switch>
{routes.map(item => {
return (
<Route
key={item.path}
path={item.path}
exact={item.exact}
render={props =>
!auth ? (
<item.component {...props} channel = {this.props.channel}/>
) : item.auth && item.auth.indexOf(auth) !== -1 ? (
<item.component {...props} channel = {this.props.channel} />
) : (
<Redirect to='/404' {...props} />
)
}></Route>
)
})}
<Redirect to='/404' />
</Switch>
</Content>
it could work but I think it is a very ugly way, any better suggestion?