Skip to content

Commit

Permalink
Added support for adding react-router and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbennet authored and athill committed May 24, 2017
1 parent b0ad89c commit ecd3697
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 23 deletions.
21 changes: 0 additions & 21 deletions packages/react-scripts/template/src/App.js

This file was deleted.

63 changes: 63 additions & 0 deletions packages/react-scripts/template/src/App.js.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { Component } from 'react';
{% if router -%}
import { HashRouter as Router, Link, Route } from 'react-router-dom';
{%- endif %}

import logo from './logo.svg';
import './App.css';
{% if redux -%}
import IncrementButton from './containers/IncrementButton';
{%- endif %}

{% if router -%}
const Home = () => (
<div>
<h3>Home</h3>
{% if redux -%}
<IncrementButton />
{%- endif %}
</div>
);
const Foo = () => (
<h3>Foo</h3>
);
const Bar = () => (
<h3>Bar</h3>
);
const Baz = () => (
<h3>Baz</h3>
);
{%- endif %}

class App extends Component {
render() {
return (
{% if router -%}
<Router>
{%- endif %}
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
{% if router -%}
<Link to="/" replace>Home</Link> | <Link to="/foo" replace>Foo</Link> | <Link to="/bar" replace>Bar</Link> | <Link to="/baz" replace>Baz</Link>
<Route exact path="/" component={Home} />
<Route path="/foo" component={Foo} />
<Route path="/bar" component={Bar} />
<Route path="/baz" component={Baz} />
{%- elif redux -%}
<IncrementButton />
{%- endif %}
</div>
{% if router -%}
</Router>
{%- endif %}
);
}
}

export default App;
12 changes: 10 additions & 2 deletions packages/react-scripts/utils/addDependencies.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
'use strict';

module.exports = (currentDependencies, { bootstrap, fontawesome, redux }) => {
module.exports = (currentDependencies, { bootstrap, fontawesome, redux, router }) => {
const boostrapDependencies = bootstrap ? { "bootstrap": "3.3.7", "react-bootstrap": "0.31.0" } : {};
const fontawesomeDependencies = fontawesome ? { "font-awesome": "4.7.0", "react-fontawesome": "1.6.1" } : {};
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" } : {};
return Object.assign({}, currentDependencies, boostrapDependencies, fontawesomeDependencies, reduxDependencies);
const routerDependencies = router ? { "react-router-dom": "4.1.1" } : {};
return Object.assign(
{},
currentDependencies,
boostrapDependencies,
fontawesomeDependencies,
reduxDependencies,
routerDependencies
);
}

0 comments on commit ecd3697

Please sign in to comment.