简体   繁体   English

如何使用反应路由器 v6 传递函数

[英]How to pass function using react router v6

I know we can pass value through route by state :我知道我们可以按state通过路由传递值:

<Link state ={someItem:""}/>

or use useNavigation()或使用useNavigation()

const nav = useNavigation()
const navTo =  () =>{
   nav("somePage",{state:{someItem:""}}
}

But whenever i try to pass function like但是每当我尝试传递函数时

const [state1,setState1] = useState('')

And i pass through state <Link state ={function:()=>{setState(123)}}/>我通过状态<Link state ={function:()=>{setState(123)}}/>

It will always return null它总是返回 null

{
    "pathname": "/search",
    "search": "",
    "hash": "",
    "state": null,
    "key": "default"
}

So my question is how to pass function through react-router (V6)所以我的问题是如何通过 react-router (V6) 传递函数

How now to pass value to components?!现在如何将价值传递给组件?!

    <Route exact path='/component' render={() => <myComponent prop={value}/>} />

How to make it that when loading it goes directly to the '/component' page, and not to '/'?!如何使它在加载时直接进入'/component'页面,而不是'/'?!

<Redirect exact from='/' to='/component'/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM