Javascript 通过嵌套路线传递道具
我有一个使用自定义路由器的应用程序 在我的根应用程序中,我有以下代码(不是完整代码): 和Javascript 通过嵌套路线传递道具,javascript,reactjs,Javascript,Reactjs,我有一个使用自定义路由器的应用程序 在我的根应用程序中,我有以下代码(不是完整代码): 和 <Component {...props} /> 正如我所想,它应该通过直接道具,但并没有任何工作。我也是新手,所以这也可能是新手的愚蠢行为。提前感谢。您正在将bedData传递给您的自定义路由,该路由在自定义路由中可以作为rest.bedData访问,您可以像这样传递给您的组件 export const TableRoute = ({ component: Component, ...
<Component {...props} />
正如我所想,它应该通过直接道具,但并没有任何工作。我也是新手,所以这也可能是新手的愚蠢行为。提前感谢。您正在将
bedData
传递给您的自定义路由,该路由在自定义路由中可以作为rest.bedData
访问,您可以像这样传递给您的组件
export const TableRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={(props) => (
authenticator.isAuthenticated === true
? <Component {...props} bedData={rest.bedData}/>
: <Redirect to={{
pathname: '/xxxx',
state: { from: props.location }
}} />
)} />
)
export const TableRoute=({component:component,…rest})=>(
(
authenticator.isAuthenticated==真
?
:
)} />
)
听起来是引入flux商店的好时机
<Component {...props} bedData={[]}/>
<Component {...props} />
export const TableRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={(props) => (
authenticator.isAuthenticated === true
? <Component {...props} bedData={rest.bedData}/>
: <Redirect to={{
pathname: '/xxxx',
state: { from: props.location }
}} />
)} />
)