Archives : May-2017

Switched to router v4 and history v4.5.1 and now history listener not working import createBrowserHistory from ‘history/createBrowserHistory’ const history = createBrowserHistory() history.listen((location, action) => { console.log(action, location.pathname, location.state) // <=== Never happens }) render( <Provider store={store}> <Router history={history}> … </Router> </Provider>, document.getElementById(‘root’) ) Any ideas why it is being ignored? Source: React Router..

Read more

How can I apply CSS rules only when a specific route is served? import React from ‘react’ import ReactDOM from ‘react-dom’ import registerServiceWorker from ‘./registerServiceWorker’ import ‘./styles/index.css’ import { Route, Switch, BrowserRouter as Router } from ‘react-router-dom’ import App from ‘./components/App’ import Life from ‘./components/Life’ ReactDOM.render( <Router> <Switch> <Route exact path=”/life” component={Life} /> <Route path=”/” ..

Read more

I’m learning from this tutorial but I keep getting this error: ‘react-router’ does not contain an export named ‘browserHistory’. The file that has react-router is this: import React from ‘react’; import ReactDOM from ‘react-dom’; import { Router, browserHistory } from ‘react-router’; import routes from ‘./routes’; ReactDOM.render( <Router history={browserHistory} routes={routes} />, document.getElementById(‘root’) ); Source: React Router ..

Read more

I’m creating an SPA and I’m trying to setup Routing in the application using the react-router-dom package version 4.1.1. My Route Definition is below: <BrowserRouter> <div> <Route exact path=”/” component={Login} /> <Route path=”/login” component={Login} /> <Route path=”404″ component={NotFound} /> <Route path=”*” component={NotFound} /> </div> </BrowserRouter> Basically, I want to setup routing so that any request ..

Read more

I am transitioning my react app from webpack-dev-server to nginx. When I go to the root url “localhost:8080/login” I simply get a 404 and in my nginx log I see that it is trying to get: my-nginx-container | 2017/05/12 21:07:01 [error] 6#6: *11 open() “/wwwroot/login” failed (2: No such file or directory), client: 172.20.0.1, server: ..

Read more

This is what my react-router code looks like render(( <Router history={browserHistory}> <Route path={CORP} component={App}> <IndexRoute component={Home} /> <Route path={“outreach”} component={OutReach}/> <Route path={“careers/m”} component={Career}/> <Route path={“members”} component={Members}/> <Redirect from=”*” to={“/home”} /> </Route> </Router> ), document.getElementById(‘app’)) But when I go to my page, I get this error in my console Uncaught ReferenceError: Redirect is not defined How ..

Read more