node.js with express how to remove the query string from the url

后端 未结 9 1385
孤街浪徒
孤街浪徒 2020-12-29 19:41

I have a button that is performing a get to my page and adding a filter to the query string. My code applies that filter to the grid...but the user can remove/edit that fil

9条回答
  •  無奈伤痛
    2020-12-29 20:30

    Use url.parse() to get the components of your address, which is req.url. The url without the query string is stored in the pathname property.

    Use express' redirect to send the new page address.

    const url = require('url'); // built-in utility
    res.redirect(url.parse(req.url).pathname);
    

    Node docs for url.

提交回复
热议问题