A
A
Aleksey ladutska2019-09-04 22:12:52
React
Aleksey ladutska, 2019-09-04 22:12:52

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

1 answer(s)
H
hzzzzl, 2019-09-04
@ladutia

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

well that is yes
you need to ask from the database from the server, of course, no matter what it is on

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question