mercredi 25 août 2021

How to route and get variables from a URL like Flask does, but in vanilla JavaScript?

In Flask, you can specify routes that look like this:

@app.route('/user/<user>')
def user_page(user):
  return render_template('user.html', user=user)

You can easily display a specific page for that route and get the value of <user>. I was wondering how I could do the same thing in a webpage with only vanilla JavaScript, as I want to make a website that has a /user/<user> page in it. It seems almost like magic to me because I would have thought it would result in a '404, page not found'.




Aucun commentaire:

Enregistrer un commentaire