Roots Discourse

Routing error in IE11


#1

Hi!

I found this problem with IE11 which stops all js to be executed. I know it’s not a desired browser, but it’s really easy to fix:

In utils/Router.js the following code gives an object error:

  fire(route, event = 'init', arg) {
    document.dispatchEvent(new CustomEvent('routed', {
      bubbles: true,
      detail: {
        route,
        fn: event,
      },
    }));

    const fire = route !== '' && this.routes[route] && typeof this.routes[route][event] === 'function';
    if (fire) {
      this.routes[route][event](arg);
    }
  }

From previous versions of Sage, this code works flawlessly:

  fire(route, event = 'init', arg) {
    const fire = route !== '' && this.routes[route] && typeof this.routes[route][event] === 'function';
    if (fire) {
      this.routes[route][event](arg);
    }
  }

The error is given by the dispatch event. So if you wrap the dispatch event portion with

if(typeof(Event) === 'function') {}

It also works as well. Is this the optimal solution?

Thank you!


#2

We just encountered this too SergiArias, thanks for posting a fix.


#3

Using a polyfill is ideal: