0

I have the following route in my express application :

app.get('/api/:URI', (req, res) => {
  doStuff();
}

The URI parameter passed is an URI encoded on the client side with encodeURIComponent()

It works fine except when the URI contains a hash.
Example: http://foo.bar/foobar/bla#blabla-313fe4ce-4f8d-48b7-b0f3-a59844402ee8
In this case the route is ignored.

On the browser side I receive a code 301, then the result of the next valid route.

If I remove the hash or, weirder, if I disable the cache on the browser side it works perfectly.

Is there any way express can ignore the hash ?

Edit : It's absolutely not a Can I use an at symbol (@) inside URLs? duplicate, the question is more about express routing and/or about browsers cache issues than about allowed characters in an URL.

Joulss
  • 1,040
  • 1
  • 14
  • 26
  • Possible duplicate of [Can I use an at symbol (@) inside URLs?](https://stackoverflow.com/questions/19509028/can-i-use-an-at-symbol-inside-urls) – Ravi Rajput Jun 28 '19 at 17:17
  • It works fine when I test it. Most likely you are using `encodeURIComponent` wrong. You need to provide a [mcve]. – Quentin Jun 28 '19 at 17:18
  • [working screenshot](https://i.imgur.com/7RxyDYE.png) – Quentin Jun 28 '19 at 17:19
  • I tried it at home and it works... So it's probably a cache issue on my browser at work. Very strange ! – Joulss Jun 28 '19 at 19:27

1 Answers1

0

Is there any way express can ignore the hash ?

I tried using the OR operator. For example,

    app.get('/blog' || '/blog#top', (request, response) => {
      ...
    });

So it works even if #top is present or not.

Storage Lenovo
  • 85
  • 1
  • 1
  • 6