Skip to content

Commit ecd3697

Browse files
jwbennetathill
authored andcommitted
Added support for adding react-router and examples
1 parent b0ad89c commit ecd3697

File tree

3 files changed

+73
-23
lines changed

3 files changed

+73
-23
lines changed

packages/react-scripts/template/src/App.js

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, { Component } from 'react';
2+
{% if router -%}
3+
import { HashRouter as Router, Link, Route } from 'react-router-dom';
4+
{%- endif %}
5+
6+
import logo from './logo.svg';
7+
import './App.css';
8+
{% if redux -%}
9+
import IncrementButton from './containers/IncrementButton';
10+
{%- endif %}
11+
12+
{% if router -%}
13+
const Home = () => (
14+
<div>
15+
<h3>Home</h3>
16+
{% if redux -%}
17+
<IncrementButton />
18+
{%- endif %}
19+
</div>
20+
);
21+
const Foo = () => (
22+
<h3>Foo</h3>
23+
);
24+
const Bar = () => (
25+
<h3>Bar</h3>
26+
);
27+
const Baz = () => (
28+
<h3>Baz</h3>
29+
);
30+
{%- endif %}
31+
32+
class App extends Component {
33+
render() {
34+
return (
35+
{% if router -%}
36+
<Router>
37+
{%- endif %}
38+
<div className="App">
39+
<div className="App-header">
40+
<img src={logo} className="App-logo" alt="logo" />
41+
<h2>Welcome to React</h2>
42+
</div>
43+
<p className="App-intro">
44+
To get started, edit <code>src/App.js</code> and save to reload.
45+
</p>
46+
{% if router -%}
47+
<Link to="/" replace>Home</Link> | <Link to="/foo" replace>Foo</Link> | <Link to="/bar" replace>Bar</Link> | <Link to="/baz" replace>Baz</Link>
48+
<Route exact path="/" component={Home} />
49+
<Route path="/foo" component={Foo} />
50+
<Route path="/bar" component={Bar} />
51+
<Route path="/baz" component={Baz} />
52+
{%- elif redux -%}
53+
<IncrementButton />
54+
{%- endif %}
55+
</div>
56+
{% if router -%}
57+
</Router>
58+
{%- endif %}
59+
);
60+
}
61+
}
62+
63+
export default App;
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
'use strict';
22

3-
module.exports = (currentDependencies, { bootstrap, fontawesome, redux }) => {
3+
module.exports = (currentDependencies, { bootstrap, fontawesome, redux, router }) => {
44
const boostrapDependencies = bootstrap ? { "bootstrap": "3.3.7", "react-bootstrap": "0.31.0" } : {};
55
const fontawesomeDependencies = fontawesome ? { "font-awesome": "4.7.0", "react-fontawesome": "1.6.1" } : {};
66
const reduxDependencies = redux ? { "redux": "3.6.0", "redux-thunk": "2.2.0", "redux-promise": "0.5.3", "redux-logger": "3.0.1", "redux-actions": "2.0.2", "react-redux": "5.0.4" } : {};
7-
return Object.assign({}, currentDependencies, boostrapDependencies, fontawesomeDependencies, reduxDependencies);
7+
const routerDependencies = router ? { "react-router-dom": "4.1.1" } : {};
8+
return Object.assign(
9+
{},
10+
currentDependencies,
11+
boostrapDependencies,
12+
fontawesomeDependencies,
13+
reduxDependencies,
14+
routerDependencies
15+
);
816
}

0 commit comments

Comments
 (0)