我尝试使用typescript来重写'Redirects (Auth)'的例子,但遇到一个问题,即函数无法像我期望的那样接收道具。
这是我的代码:
路由器设置和私有路由器的功能:
export default () => (
<Router>
<Switch>
<PrivateRoute exact path="/welcome" component={Welcome}/>
<Route component={NoMatch}/>
</Switch>
</Router>)
const PrivateRoute = (component: any, ...rest: Array<any>) => {
console.log(component, rest)
return (
<Route {...rest} render={props => (
isAuthenticated() ? (
<div>
<Header/>
<Sider/>
<div className="content slide-in">
<component {...props}/>
</div>
</div>
) : (
<Redirect to={{
pathname: '/',
state: { from: props.location }
}}/>
)
)}/>
)}
我希望组件的参数是'welcome'的组件,其余的参数是其他参数,例如'exact'和'path',但实际上如上图所示得到参数。
任何人都可以帮我解决这个问题吗? 非常感谢!