question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

this.context.router undefined in IE10

See original GitHub issue

We’re currently running version 0.13.3 and are using the State Mixins to access .getParams() throughout the our app. Specifically we are calling the method in componentDidMount and componentWillReceiveProps.

When running the app in IE10, we get the error Unable to get property 'getCurrentParams' of undefined or null reference, which is being traced back to the getParams method of the State object:

screenshot 2015-06-10 11 38 30

I should also note that we’re using Webpack and the Babel loader.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
leonid-shevtsovcommented, Sep 7, 2015

I want to add that this is caused by Babel classes inheritance not entirely supported in IE<11, and can be fixed by adding an additional Babel transformer.

https://babeljs.io/docs/advanced/caveats/#classes-10-and-below-

1reaction
bsbeekscommented, Jul 2, 2015

To summarize:

getParams()

Defining contextTypes appeared to have fixed any issues in IE10 for @coryvirok. However, it did not work for me. Instead I had to implement the params through the RouteHandler props as outlined in the docs (https://github.com/rackt/react-router/blob/v0.13.3/docs/guides/overview.md#dynamic-segments):

Router.run(routes, function (Handler, state) {
  var params = state.params;
  React.render(<Handler params={params}/>, document.body);
});

// and then pass the params down to every use of `<RouteHandler/>`
<RouteHandler {...this.props}/>

// Inbox ends up looking like this
var Inbox = React.createClass({
  render: function () {
    return (
      <div>
        <Toolbar/>
        <Messages/>
        <RouteHandler {...this.props}/>
      </div>
    );
  }
});

// and Message changes to:
var Message = React.createClass({
  render: function () {
    return (
      <div>{this.props.params.messageId}</div>
    );
  }
});

isActive()

If you are using this method and need compatibility in IE10, you will need to implement a custom method to handle this. I decided to create a Router Utils that housed this method:

isActive (pathParts) {
  const path = window.location.hash;
  const routes = path.split('/').filter(string => {
    return string.length && string !== '#';
  });

  const isActive = pathParts.filter(route => {
    return routes.indexOf(route) < 0;
  });

  return !isActive.length;
}

Though it’s not the best fix, it did resolve any issues with IE10. The downside to this approach is you don’t have access to the route names. Instead you have to target parts of the url. This isn’t a big issue for me since my route names and paths are consistent. An added bonus to this approach is I can check if a child route belongs to a parent route by passing in the parent route path:

// if my current path is /myparent/children/:id
// then within my children components I can run:
RouterUtils.isActive(['myparent']); // returns true

I haven’t tested other methods that utilize this.context.router, but I’m assuming you’ll run into similar issues in IE10.

Read more comments on GitHub >

github_iconTop Results From Across the Web

this.context.router undefined in IE10 on extended class in 1.0 ...
I'm using ES6-Syntax and fail to access this.context.router, but only in IE10 and IE9. My code looks like this basePage.jsx export default class...
Read more >
Why is my context.router undefined in my react component?
I have tried to bind this to the function in the constructor , but it still is undefined . Also, when I put...
Read more >
spPageContextInfo.siteServerRelativeUrl is undefined
I ran into a similar issue, but it was caught during build as I am using CreateReactApp , and they have a check...
Read more >
Is your Vue app not working in IE 11? Here's how to fix it.
The main reason why your Vue app is breaking in IE11 is because the browser does not support modern JavaScript syntax. By that...
Read more >
Handling common JavaScript problems - MDN Web Docs
Expand the showHeroes scope — you can see from this that the heroes variable is undefined , indicating that accessing the members property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found