I have a bootstrap+react theme that was using react-router 1.x and hashHistory and I wanted to remove the hash so followed this advice. Initially I tried to do this while having the 1.x version and I was unable to do it so I've decided to upgrade react-router to 2.x. After installing react-router 2.x the app worked because it was still using hashHistory but when I replaced it with browserHistory:
- it showed a grey screen
- the HTML of the app had only the
<noscript data-reactid=".0"></noscript>tag inside it - the React Developer Tools showed me that the router had a
nullinside it - I also checked the Network tab and all files were downloaded properly, and had the right content
surprisingly the was nothing printed in the JavaScript Console, no error/no warnging (I'm really shocked about this, but I'm new React, I would like to know what to do in situations like this). Here are my changes to
Router.jsx:import React from 'react' import {render} from 'react-dom' -import {Router} from 'react-router' +// import {Router} from 'react-router' +import { Router, Route, Link, browserHistory } from 'react-router' +// import { useRouterHistory } from 'react-router' +// import { createHashHistory } from 'history' +// import { createBrowserHistory } from 'history'` import History from '../components/layout/navigation/classes/History.js'; import Routes from './Routes.jsx'; +// const appHistory = useRouterHistory(createHashHistory)({ queryKey: false }) + var rootInstance = render(( - <Router history={History}> + <Router history={browserHistory}> {Routes} </Router> ), document.getElementById('smartadmin-root'));`
The backend uses the Phoenix Framework.
Later Edit:
Here you have the hashHistory version that works
https://gitlab.com/blockbuster/react-router-2-with-hash-working/tree/master
And here is the browserHistory version that doesn't:
https://gitlab.com/blockbuster/react-router-2-with-browserHistory-not-working/tree/master
The react code for both can be found under the src directory.
To run the app you need to have Elixir, Phoenix and Postgresql installed, to get backend dependencies( run $ mix deps.get), get frontend dependecies( npm install and bower install), to change the database username and password in config/dev.exs, to create and migrate the database mix ecto.create && mix ecto.migrate and finally run mix phoenix.server.