Skip to content

Commit 9c097cb

Browse files
authored
Merge pull request #41 from piotrwitek/browser-history-with-api-fallback
Browser history with api fallback
2 parents f29c1c7 + 57adb82 commit 9c097cb

File tree

6 files changed

+310
-89
lines changed

6 files changed

+310
-89
lines changed

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
<head>
55
<meta charset="utf-8">
6-
<meta name="description" content="">
6+
<meta name="description" content>
77
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
88
<title>React / Redux / TypeScript - starter-kit</title>
9-
<link rel="stylesheet" href="assets/loader-styles.css">
10-
<link rel="stylesheet" href="https://unpkg.com/blaze@3.2.0">
9+
<link href="assets/loader-styles.css" rel="stylesheet">
10+
<link href="https://unpkg.com/blaze@3.2.0" rel="stylesheet">
1111
</head>
1212

1313
<body>
@@ -36,7 +36,7 @@
3636
// hot-reload config
3737
SystemJS.import('systemjs-hot-reloader').then(function(HotReloader) {
3838
// if you're running server on custom port please remember to update below
39-
new HotReloader.default('http://localhost:8888');
39+
new HotReloader.default('http://localhost:3000');
4040
});
4141
// load main module of your app with SystemJS
4242
SystemJS.trace = true;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"husky": "^0.11.8",
4949
"jest": "^17.0.3",
5050
"jspm": "0.17.0-beta.32",
51-
"jspm-hmr": "^0.5.0",
51+
"jspm-hmr": "1.0.0-0",
5252
"regenerator": "^0.9.5",
5353
"shelljs": "^0.7.5",
5454
"shx": "^0.2.1",

server.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
'use strict';
22
const jspmHmrServer = require('jspm-hmr');
3+
34
const options = {
4-
open: true
5+
fallback: '/index.html',
6+
verbose: false,
57
};
68

7-
jspmHmrServer.start(options);
9+
// SERVER
10+
const server = jspmHmrServer.createServer(options);
11+
12+
server
13+
.listen(3000, (err) => {
14+
console.log('[debug] %j', server.address());
15+
console.log('\n>>> hit CTRL-C twice to exit <<<\n');
16+
})
17+
.on('error', function (err) {
18+
if (err.code === 'EADDRINUSE') {
19+
console.log(`\n[WARNING] Selected address is in use: ${URL}`);
20+
console.log(`[WARNING] Please try again using different port or address...\n`);
21+
22+
process.exit();
23+
}
24+
});

src/app.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
import * as React from 'react';
33
import * as ReactDOM from 'react-dom';
44
import { Provider } from 'react-redux';
5-
import { Router, Route, hashHistory } from 'react-router';
5+
import { Router, Route, browserHistory } from 'react-router';
66
import { syncHistoryWithStore } from 'react-router-redux';
77
// app imports
88
import { MainLayout } from './layouts/main-layout';
99
import { HomeContainer } from './containers/home-container/index';
1010
import { CssModulesContainer } from './containers/css-modules-container/index';
11+
import NotFoundContainer from './containers/not-found/index';
1112
import CurrencyConverterContainer from './containers/currency-converter-container/index';
1213

1314
import { store } from './store/index';
14-
const history = syncHistoryWithStore(hashHistory, store) as any;
15+
const history = syncHistoryWithStore(browserHistory, store) as any;
1516

1617
function App() {
1718
return (
@@ -21,6 +22,7 @@ function App() {
2122
<Route path="/" component={HomeContainer} />
2223
<Route path="/currency-converter" component={CurrencyConverterContainer} />
2324
<Route path="/css-modules" component={CssModulesContainer} />
25+
<Route path="*" component={NotFoundContainer} />
2426
</Route>
2527
</Router>
2628
</Provider>

src/containers/not-found/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
import { Link } from 'react-router';
3+
import { PageSection } from '../../components/page-section';
4+
import { PageHero } from '../../components/page-hero';
5+
6+
export default function () {
7+
return (
8+
<article>
9+
<PageHero title="404 Not Found" subtitle="Page not found" />
10+
<PageSection className="o-container o-container--small u-centered">
11+
<Link to="/">Back to Home</Link>
12+
</PageSection>
13+
<br />
14+
</article>
15+
);
16+
};

0 commit comments

Comments
 (0)