Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render view with anchor tag in express.js

How do you render a page, but with the anchor tag as well in express.js routes?

So: website.com/route#id-of-html-element

like image 990
Costa Michailidis Avatar asked Feb 07 '23 13:02

Costa Michailidis


1 Answers

You can't. The anchor tag is not sent between client and server. Only the client deals with it. I think the only way to do this would be something like this:

res.render ('view', {anchor: 'anchor'});

in Express, then in your template put some javascript:

if anchor
    script.
        window.onload = window.location.hash = '#{anchor}';
like image 64
anthonygore Avatar answered Feb 10 '23 23:02

anthonygore