mhaagens / react-mobx-react-router4-boilerplate

React, React-Router 4, MobX and Webpack 2-boilerplate with async routes.
560 stars 137 forks source link

UI wouldn't load; keep getting error: TypeError: this.context.router.createHref is not a function. #24

Closed gkbn closed 7 years ago

gkbn commented 7 years ago

TypeError: this.context.router.createHref is not a function. (In 'this.context.router.createHref(typeof to === 'string' ? { pathname: to } : to)', 'this.context.router.createHref' is undefined)

The UI shows red background with the above message and then a ton of function names one after the other. I am new to React, MobX and even Javascript. Wanted to develop a website and thought this is the ideal project for me as I want to use MobX. Cloned the repo and executed "npm install" and "npm start". Did not edit any code, so not sure why the error. Please help!

orouz commented 7 years ago

upgrade react router to 4.0.0

gkbn commented 7 years ago

Thank you @orouz! I have tried installing react 4 again even though I thought it was already at that. There is no difference - still getting the same error.

Ihatetomatoes commented 7 years ago

@gkbn I have removed all references to react-router-dom and react-router from the package.json and also deleted the related folders from node_modules.

Then I simply installed the latest version of react-router-dom:

npm i -D react-router-dom@next

Then npm start worked fine. Hope that helps.

gkbn commented 7 years ago

@Ihatetomatoes Thank you so much! That's exactly what I had to do and it fixed the issue. I did it in slightly different way though. Instead of manually deleting the entries from package.json and then the related folders from node_modules, I ran the uninstall commands below: npm uninstall react-router-dom --save-dev npm uninstall react-router --save-dev

Appreciate you taking time to respond in detail. Was a huge help when I was stuck.