3

I have a React app using React-Router that I'm embedding into an Electron app. It works great when using hashHistory, but when I switch to browserHistory, nothing works (e.g. the page doesn't load at all). No errors or anything, just a blank page and a noscript loaded into the root. Any thoughts why this could be?

EDIT: This was the case with the previous version of React-Router, and on the version I just updated to (2.0.0). Also using the latest stable React.

Ruben Martinez Jr.
  • 3,199
  • 5
  • 42
  • 76
  • any update on how you solved this? I get `Warning: [react-router] Location "/" did not match any routes` when I try to use react-router :/ – corasan Oct 09 '16 at 19:05
  • I was never able to get this working and just assumed it was a me thing. What I ended up doing was declaring a global variable so I knew when I was in my electron app, and then passing either `browserHistory` or `hashHistory` to RR based on that variable. – Ruben Martinez Jr. Oct 10 '16 at 15:49
  • See if this helps: http://stackoverflow.com/questions/36505404/how-to-use-react-router-with-electron – Nah Jan 07 '17 at 16:08

3 Answers3

2

Because browserHistory is only used for http web, so electron.BrowserWindow.loadURL('http://localhost:8080').

But hashHistory is used for local file and http web, so electron.BrowserWindow.loadURL('file:path').

MWiesner
  • 8,868
  • 11
  • 36
  • 70
tiango
  • 21
  • 2
0

I can't see your code, but my browserHistory worked correctly. My package.json dependencies:

"history": "^1.13.0"

then in my main.js:

import React from 'react';
import ReactDOM from 'react-dom';
import {Router,Route} from 'react-router';
import createBrowserHistory from 'history/lib/createBrowserHistory'
import route from './route';

let history = createBrowserHistory();
ReactDOM.render((
  <Router history={history}>
    {route}
  </Router>
),document.getElementById('app'));

please ignore my route.js file

ThinkCat
  • 1
  • 2
  • In RR 2.0.0 you can import browserHistory directly from RR, which I'm doing. It uses `history@2.0.0`. – Ruben Martinez Jr. Feb 16 '16 at 18:05
  • @RubenMartinezJr. Sorry, I ignored your RR version. I tried RR 2.0 and imported browserHistory directly from RR just now, the project worked fine ,page can reload correctly, everything worked fine ,and the URL is restful style. Your page can not load at all, maybe some error occurred in other place. My test project is here:[https://github.com/ThinkCats/React-Router-Starter](https://github.com/ThinkCats/React-Router-Starter), wish that will help you. – ThinkCat Feb 17 '16 at 11:48
0

maybe upgrade the history?

"history": "^1.17.0",
caffeinescript
  • 1,365
  • 2
  • 13
  • 27