Hash support for js routes

Hi,

I have an account page where you can edit your profile via a modal with a form in it. The modal loads just fine and I use some js to hide/show certain elements based on the form input. This modal also provides an option to reset the user’s password. Therefore I wanted to create a shortcut in the menu with a reset password link. The link looks like “https://domain/account/#editProfile”. I have JS code in my common.js that can detect the # and then fires the .modal('show) function.

However, although this works fine and the modal is being show when clicking on the link from anywhere on the website, the specific js for /account doesn’t seem to be loaded. So showing/hiding of form fields nog longer works. I assume the router recognizes the link with the hash as a separate route instead of being part of /account.

I have no clue on how to get the router support hashes in a url. Any help would be appreciated.

Thanks, Nick

The router uses the class on <body> so it shouldn’t actually have anything to do with the URL that you’re at. I’m a little unclear re: what you’re doing, but if you have site-wide code that looks for the hash and fires some code when that link is clicked without taking the user to the /account/ url then your JS for /account/ isn’t firing because the rounter doesn’t detect the account class in the <body>. There are a number of ways you could architect your JS to get around that (move your show/hide field code into the common route; refactor that logic out into methods and then call those methods in multiple locations; etc).

1 Like

Thanks for your reply. Your hint helped me find out whats wrong. I used a wrong page url that linked to a different page, however it uses the same page template as the page I actually needed to link to. Bit confusing perhaps but it came down to this. Because I was link to a wrong a page the page body class was incorrect and therefor the js did not fire. Now I got it linked to the correct page and the js is fired just fine. Everything works as expected.

Thanks for your insights

1 Like