Answer the question
In order to leave comments, you need to log in
How can I make a short link in React?
For example, there is a link localhost/mobile/samsung which displays the ListPhones component.
But I need to create a new link in a shorter form: localhost/m/mxkt, the user can get it by clicking on the button (but each time the link is created a new localhost/m/.....). After that, the user can follow the new link that he received "localhost/m/mxkt" and get to the same page as the regular link "localhost/mobile/samsung". Is it really possible to do this through a router? or you need to connect other languages, for example php, and create such links and checks with redirects there.
As I understand it, these links should be stored in the database and checked for their existence before being used in the router.
localhost/mobile/samsung - this can be either localhost/m/mxkt or localhost/m/asfa or localhost/m/fa (assuming they were created when the user clicked the button to generate them).
Answer the question
In order to leave comments, you need to log in
i would do that
const shortUrl = this.props.match.params.url // mxkt
const longUrl = await fetch('/api/getlink/' + shortUrl) // mobile/samsung
this.props.history.push('/m/' + longUrl) // localhost/mobile/samsung
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question