在路线ReactJs中将props传递给功能组件

问题描述

我的路线如下:

<Switch>
  <Redirect
    path="/google/auth/success"
    to={{pathname: "/sign-in",state: {propsTest: "Sample property send"}}}
  />
  <Route
    component={SignIn}
    exact
    path="/sign-in"
  />
  ...
</Switch>

SignIn组件是一个功能组件,如下所示:

const SignIn = ({ isLoggedIn,authorization,signin,error }) => {
...
return (
...
)
}

我想将propsTest传递给此SignIn组件,我尝试这样做:

const SignIn = ({ isLoggedIn,error,propsTest }) => {

...
console.log("Property passed to SignIn",propsTest);
...
return (
...
)
}

如何在SignIn组件中获取propsTest。我找到了一些有关“类组件”而不是“功能组件”的示例。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)