Router.push({pathname: '/card', query:{data: ObjectData}})
I get query as empty value could not pass object into it
You can access it inside the <Items> component like this. import React, { Component } from "react"; import { withRouter } from "next/router" class Items extends Component { render() { const { query } = this.
There is no way to pass data between pages with Next's router. You would have to either use query strings as you mentioned, sessionStorage, or a state management option like Redux or React's Context API. You could then put that in your pages/_app.
Props are passed from a parent component to its child components. What you are asking is to pass props between sibling components (ie. page) which I don't think has a straightforward way to do so. Maybe you can try using React's Context API so that your Test2 is not using any hard-coded value.
you can pass your params like this case:
router.push({
pathname: '/card',
query: { data: JSON.stringify(ObjectData)}
})
and you can get params in card component like this:
JSON.parse(props.router.query.data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With