This is my main app file:
import React from 'react';
import { render } from 'react-dom';
import { browserHistory, Router, Route, IndexRoute } from 'react-router';
// Components
import Main from './components/core/Main.component';
import NotFound from './components/core/NotFound.component';
import About from './components/About.component';
import TeaTimer from './components/TeaTimer.component';
// App css
require('style!css!sass!applicationStyles');
render(
(<div>
<Router history={browserHistory}>
<Route component={Main} path="/">
<IndexRoute component={TeaTimer} />
<Route component={About} path="/about"/>
</Route>
<Route component={NotFound} path="*"/>
</Router>
</div>),
document.querySelector('#app')
);
This is my Main component:
import React, { Component } from 'react';
class Main extends Component {
render() {
return (
<div>
{this.props.children}
</div>
)
}
}
Main.propTypes = {
children: React.PropTypes.object
}
export default Main;
This is my express server setup:
var express = require('express');
// Create our app
var app = express();
const PORT = process.env.PORT || 3000;
app.use(function (req, res, next){
if (req.headers['x-forwarded-proto'] === 'https') {
res.redirect('http://' + req.hostname + req.url);
} else {
next();
}
});
app.use(express.static('public'));
app.listen(PORT, function () {
console.log('Express server is up on port ' + PORT);
});
Now when I open the browser and go to http://localhost:3000
I get the TeaTimer component. Same for http://localhost:3000/#/
, same for http://localhost:3000/#/about
, same for an undefined route - http://localhost:3000/#/sdnaipwnda[j
.
But when I go to http://localhost:3000/about
I get:
Cannot GET /about
What am I doing wrong?
If you need more info please ask and I will add it to the question, or checkout this git repo.