lundi 2 décembre 2019

How to keep search query in a sharable URL

(Web dev newbie here)

I have created a simple one page React App that has an input form and, after a button click, calls an API and displays the response.

I would like to be able to share an URL that would take people directly to the app and would search automatically.

For instance, a user goes to the app (http://myapp.com/) and inputs sophie and 20. He then gets information about that person (a fetch is made with this input) - this is already working. But also, the url changes to something like this:

http://myapp.com/person?name=sophie&age=20

The user would now be able to share this URL and people would be redirected to the app which would show data about sophie, after calling the api with sophie and 20 as input again (without the user having to input anything).

What is the best way for doing this?




Aucun commentaire:

Enregistrer un commentaire