Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get url after "#" in express.js middleware request

I need to get url on server middleware (using express.js). I use req.url but when url starts from /#some/url req.url returns /...

The same with req.path..

Is there a way to get url after # in express.js?

like image 872
Kosmetika Avatar asked Jul 19 '13 10:07

Kosmetika


People also ask

How do I find my URL path?

To split the URL to get URL path in with JavaScript, we can create a URL instance from the URL string. Then we can use the pathname property to get the URL path. For instance, we write: const url = 'http://www.example.com/foo/path2/path3/path4'; const { pathname } = new URL(url); console.


1 Answers

No. The part of the URL starting with the # symbol is never sent to the server.

The # symbol in an URL is to introduce the fragment identifier. This is used to link to a specific part of the page. If a browser loads /#some/url, it will effectively load /, and skip to the HTML element with id="some/url" (if present). The fragment identifier is only relevant to the browser, so it is not sent with the HTTP request.

What you however can do, is using client side Javascript to read out the value of window.location.hash and send it to the server using an XMLHttpRequest. (See other Stack Overflow post.)

like image 156
user5207081 Avatar answered Oct 02 '22 00:10

user5207081