D
D
DavidWork2020-07-06 14:57:02
JavaScript
DavidWork, 2020-07-06 14:57:02

React how to open a product card in a new browser window without losing data?

Good afternoon.
The task was to open a product card in a new browser window when clicking on the details button.
But the problem is that the data in the new window is lost. And a blank page is rendered.
Please tell me how to solve this problem.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Tikhon Ermakov, 2020-07-06
@the_goldmayer

I don't think this is a very good approach in using SPA.
The solution, I think, is to write the necessary data to localStorage before opening a new tab.
Read more about localStorage here .

K
kyzinatra, 2020-07-06
@kyzinatra

IndexDB if local.
If for good, then receive data from the server.
or you can use Router, but as far as I understand it will be necessary to do everything in 1 tab

H
hzzzzl, 2020-07-06
@hzzzzl

react-router-dom
https://reactrouter.com/web/guides/quick-start

The task was to open a product card in a new browser window when clicking on the details button.

i.e. something along the lines of
<a href="/item/item_name" target="_blank">Go to item</a>

and somewhere in the app to catch
<Route path='/item/:item_name' exact render={props => <ItemPage {...props} />} />

I’m not responsible for the modern router-dom syntax, I haven’t touched it for a while

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question