Menu buttons cause URL to concatenate and grow indefinitely - here's a fix to that bug

Have you ever noticed that the menu buttons in Knack cause the URL in your address bar to grow each time you clik on one?

But it doesn't do that on all Apps. I have some that have the bug and others that don't. Knack has acknowledged the problem and siad they were working on it. But this was back in July 2019 and my patience has run out!

So here's my solution, and it works in all cases. Enjoy!

Norm

$(document).on('knack-scene-render.any', function (event, scene) {
fixLinkButtons();
});

///////////////////////////////////////////////////////////
//Remove buggy extra last portion of URL added by Knack in menu buttons.
//Ex: turns this https://mycompany.knack.com/myapp#mypage1/mypage2
// into this https://mycompany.knack.com/myapp#mypage2
function fixLinkButtons() {
var linkButtons = document.getElementsByClassName('kn-button kn-link');
for (var i = 0; i < linkButtons.length; i++) {
var link = linkButtons[i].getAttribute('href');
var i1 = link.indexOf('#') + 1;
var i2 = link.lastIndexOf('/') + 1;
if (i2 > i1) {
var endStr = link.substring(i2);
link = link.substring(0, i1) + endStr;
linkButtons[i].setAttribute('href', link);
}
}
}