Changing hash throw: Uncaught Error: Syntax error, unrecognized expression I want to change the hash in the URL when I trigger an action (a click for instance) using a pattern like #/param-1=foo&amp;param-2=bar
In a fresh Drupal 8 theme, when I try this, I got an error saying
Uncaught Error: Syntax error, unrecognized expression: #/test=0
It works fine when I try with #param1-foo_param2-bar but I would like more flexibility. It looks like jquery is trying to consider the hash as a selector and returns an error that says it's not a valid selector.
Here is the code I use on a fresh classy based theme:
(function ($, Drupal) {
    Drupal.behaviors.myModuleBehavior = {
        attach: function (context, settings) {
            $('.layout-container', context).once('myModuleBehavior').each(function () {
                $('.site-name a').on('click', function (event) {
                    event.preventDefault();
                    event.stopPropagation();
                    console.log(&quot;clicking on logo&quot;);
                    window.location.hash = &quot;/test=0&quot;;
                });
            });
        }
    };
})(jQuery, Drupal);

And here is the result I get from chrome console:
Thanks to @Alfred Armstrong pointing down form.js. It seems this event is responsible of that behaviour:  

 $(window).on('hashchange.form-fragment', debouncedHandleFragmentLinkClickOrHashChange);


It looks like unbinding it in my custom .js does the trick. We won't benefit from the scroll functionality form.js provides, but we could recreate it with:

$(window).off('hashchange.form-fragment').on('hashchange', function() {
    //something that scroll 
});