Skip to content

Commit

Permalink
[changed] Support React Router v2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Dec 31, 2015
1 parent faf6558 commit 483a863
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "airbnb",
"parser": "babel-eslint",
"rules": {
"comma-dangle": 0,
"eqeqeq": [2, "allow-null"],
"id-length": 0
"eqeqeq": [2, "allow-null"]
}
}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Integration between [React Router](https://github.com/rackt/react-router) and [R
Wrap your React-Bootstrap element in a `LinkContainer` to make it behave like a React Router `Link`:

```js
<LinkContainer to="/foo" query={{bar: "baz"}}>
<LinkContainer to={{ pathname: '/foo', query: { bar: 'baz' } }}>
<Button>Foo</Button>
</LinkContainer>
```
Expand All @@ -20,14 +20,16 @@ As with React Router's `Link`, returning `false` from an `onClick` handler on `L

## Installation

**Note:** Releases from v0.20.0 onward only support React Router v2.x. For React Router 1.x support, use v0.19.3 or earlier.

```
npm install react-router-bootstrap
```

You will also want to have React Router and React-Bootstrap.

```
npm install react-router@latest react-bootstrap
npm install react-router react-bootstrap
```

## Contributing
Expand Down
72 changes: 36 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,53 @@
},
"homepage": "https://github.com/react-bootstrap/react-router-bootstrap",
"peerDependencies": {
"react": ">=0.13.0",
"react-router": ">=1.0.0-rc3"
"react": ">=0.14.0",
"react-router": ">=2.0.0-rc2"
},
"devDependencies": {
"babel": "^5.8.23",
"babel-core": "^5.8.25",
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"bootstrap": "^3.3.5",
"babel": "5.x",
"babel-core": "5.x",
"babel-eslint": "^4.1.6",
"babel-loader": "5.x",
"bootstrap": "^3.3.6",
"colors": "^1.1.2",
"css-loader": "^0.19.0",
"es5-shim": "^4.1.14",
"eslint": "^1.7.1",
"eslint-config-airbnb": "^0.1.0",
"eslint-plugin-babel": "^2.1.1",
"eslint-plugin-mocha": "^1.0.0",
"eslint-plugin-react": "^3.5.1",
"file-loader": "^0.8.4",
"history": "^1.12.5",
"html-webpack-plugin": "^1.6.2",
"karma": "^0.13.11",
"karma-cli": "^0.1.1",
"karma-mocha": "^0.2.0",
"karma-mocha-reporter": "^1.1.1",
"karma-phantomjs-launcher": "^0.2.1",
"css-loader": "^0.23.1",
"es5-shim": "^4.4.1",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^2.1.1",
"eslint-plugin-babel": "^3.0.0",
"eslint-plugin-mocha": "^1.1.0",
"eslint-plugin-react": "^3.13.1",
"file-loader": "^0.8.5",
"history": "^1.17.0",
"html-webpack-plugin": "^1.7.0",
"karma": "^0.13.16",
"karma-cli": "^0.1.2",
"karma-mocha": "^0.2.1",
"karma-mocha-reporter": "^1.1.5",
"karma-phantomjs-launcher": "^0.2.2",
"karma-sinon-chai": "^1.1.0",
"karma-sourcemap-loader": "^0.3.6",
"karma-webpack": "^1.7.0",
"less": "^2.5.3",
"less-loader": "^2.2.1",
"less-loader": "^2.2.2",
"lodash": "^3.10.1",
"mocha": "^2.3.3",
"mocha": "^2.3.4",
"mt-changelog": "^0.6.2",
"node-libs-browser": "^0.5.3",
"phantomjs": "^1.9.18",
"react": "^0.14.0",
"react-bootstrap": "^0.27.2",
"react-dom": "^0.14.0",
"react-router": "^1.0.0-rc3",
"release-script": "^0.5.4",
"rimraf": "^2.4.3",
"phantomjs": "^1.9.19",
"react": "^0.14.5",
"react-bootstrap": "^0.28.1",
"react-dom": "^0.14.5",
"react-router": "^2.0.0-rc4",
"release-script": "^0.5.6",
"rimraf": "^2.5.0",
"shelljs": "^0.5.3",
"style-loader": "^0.12.4",
"url-loader": "^0.5.6",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.12.0",
"yargs": "^3.27.0"
"style-loader": "^0.13.0",
"url-loader": "^0.5.7",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0",
"yargs": "^3.31.0"
},
"files": [
"README",
Expand Down
32 changes: 12 additions & 20 deletions src/LinkContainer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This is largely taken from react-router/lib/Link.

import React from 'react';
import {Link} from 'react-router';
import { Link } from 'react-router';

export default class LinkContainer extends React.Component {
constructor(props, context) {
Expand All @@ -24,23 +24,15 @@ export default class LinkContainer extends React.Component {
}

render() {
const {history} = this.context;
const {onlyActiveOnIndex, to, query, hash, children, ...props} =
this.props;

delete props.state;
const { router } = this.context;
const { onlyActiveOnIndex, to, children, ...props } = this.props;

props.onClick = this.onClick;

// Ignore if rendered outside the context of history, simplifies unit testing.
if (history) {
props.href = history.createHref(to, query);

if (hash) {
props.href += hash;
}

props.active = history.isActive(to, query, onlyActiveOnIndex);
// Ignore if rendered outside Router context; simplifies unit testing.
if (router) {
props.href = router.createHref(to);
props.active = router.isActive(to, onlyActiveOnIndex);
}

return React.cloneElement(React.Children.only(children), props);
Expand All @@ -49,17 +41,17 @@ export default class LinkContainer extends React.Component {

LinkContainer.propTypes = {
onlyActiveOnIndex: React.PropTypes.bool.isRequired,
to: React.PropTypes.string.isRequired,
query: React.PropTypes.object,
hash: React.PropTypes.string,
state: React.PropTypes.object,
to: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.object,
]).isRequired,
onClick: React.PropTypes.func,
disabled: React.PropTypes.bool.isRequired,
children: React.PropTypes.node.isRequired
};

LinkContainer.contextTypes = {
history: React.PropTypes.object
router: React.PropTypes.object
};

LinkContainer.defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion tests/IndexLinkContainer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import * as ReactBootstrap from 'react-bootstrap';
import ReactDOM from 'react-dom';
import {IndexRoute, Route, Router} from 'react-router';
import { IndexRoute, Route, Router } from 'react-router';

import IndexLinkContainer from '../src/IndexLinkContainer';

Expand Down
25 changes: 18 additions & 7 deletions tests/LinkContainer.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import createMemoryHistory from 'history/lib/createMemoryHistory';
import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import * as ReactBootstrap from 'react-bootstrap';
import ReactDOM from 'react-dom';
import {Route, Router} from 'react-router';
import { Route, Router } from 'react-router';
import createMemoryHistory from 'react-router/lib/createMemoryHistory';

import LinkContainer from '../src/LinkContainer';

Expand All @@ -23,7 +23,13 @@ describe('LinkContainer', () => {
<Route
path="/"
component={() => (
<LinkContainer to="/foo" query={{bar: 'baz'}} hash="#the-hash">
<LinkContainer
to={{
pathname: '/foo',
query: { bar: 'baz' },
hash: '#the-hash'
}}
>
<Component>Foo</Component>
</LinkContainer>
)}
Expand All @@ -43,7 +49,12 @@ describe('LinkContainer', () => {
<Route
path="/"
component={() => (
<LinkContainer to="/foo" query={{bar: 'baz'}}>
<LinkContainer
to={{
pathname: '/foo',
query: { bar: 'baz' }
}}
>
<Component>Foo</Component>
</LinkContainer>
)}
Expand Down Expand Up @@ -84,7 +95,7 @@ describe('LinkContainer', () => {
const anchor = ReactTestUtils.findRenderedDOMComponentWithTag(
router, 'A'
);
ReactTestUtils.Simulate.click(anchor, {button: 0});
ReactTestUtils.Simulate.click(anchor, { button: 0 });

const target = ReactTestUtils.findRenderedDOMComponentWithClass(
router, 'target'
Expand Down Expand Up @@ -116,7 +127,7 @@ describe('LinkContainer', () => {
const anchor = ReactTestUtils.findRenderedDOMComponentWithTag(
router, 'A'
);
ReactTestUtils.Simulate.click(anchor, {button: 0});
ReactTestUtils.Simulate.click(anchor, { button: 0 });

expect(onClick).to.have.been.calledOnce;
expect(childOnClick).to.have.been.calledOnce;
Expand Down Expand Up @@ -183,7 +194,7 @@ describe('LinkContainer', () => {
router, Component
);
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(component),
{button: 0}
{ button: 0 }
);

const target = ReactTestUtils.scryRenderedDOMComponentsWithClass(
Expand Down
2 changes: 1 addition & 1 deletion tests/visual/ButtonVisual.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar';
import Button from 'react-bootstrap/lib/Button';
import {Link} from 'react-router';
import { Link } from 'react-router';

import LinkContainer from '../../src/LinkContainer';

Expand Down
2 changes: 1 addition & 1 deletion tests/visual/Home.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Link} from 'react-router';
import { Link } from 'react-router';

export default () => (
<div>
Expand Down
2 changes: 1 addition & 1 deletion tests/visual/ListGroupItemVisual.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ListGroup from 'react-bootstrap/lib/ListGroup';
import ListGroupItem from 'react-bootstrap/lib/ListGroupItem';
import {Link} from 'react-router';
import { Link } from 'react-router';

import LinkContainer from '../../src/LinkContainer';

Expand Down
2 changes: 1 addition & 1 deletion tests/visual/MenuItemVisual.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar';
import MenuItem from 'react-bootstrap/lib/MenuItem';
import SplitButton from 'react-bootstrap/lib/SplitButton';
import {Link} from 'react-router';
import { Link } from 'react-router';

import LinkContainer from '../../src/LinkContainer';

Expand Down
2 changes: 1 addition & 1 deletion tests/visual/NavItemVisual.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import Nav from 'react-bootstrap/lib/Nav';
import NavItem from 'react-bootstrap/lib/NavItem';
import {Link} from 'react-router';
import { Link } from 'react-router';

import LinkContainer from '../../src/LinkContainer';

Expand Down
9 changes: 5 additions & 4 deletions tests/visual/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import Grid from 'react-bootstrap/lib/Grid';
import ReactDOM from 'react-dom';
import {IndexRoute, Route, Router} from 'react-router';
import { IndexRedirect, Route, Router } from 'react-router';
import hashHistory from 'react-router/lib/hashHistory';

import ButtonVisual from './ButtonVisual';
import Home from './Home';
Expand All @@ -11,7 +12,7 @@ import NavItemVisual from './NavItemVisual';

import 'bootstrap/less/bootstrap.less';

const App = ({children}) => (
const App = ({ children }) => (
<Grid>
<h1>React-Router-Bootstrap Module Visual Test</h1>
{children}
Expand All @@ -22,9 +23,9 @@ const mountNode = document.createElement('div');
document.body.appendChild(mountNode);

ReactDOM.render(
<Router>
<Router history={hashHistory}>
<Route path="/" component={App}>
<IndexRoute onEnter={(_, replaceWith) => replaceWith(null, '/home')} />
<IndexRedirect to="/home" />
<Route path="home" component={Home} />

<Route path="button" component={ButtonVisual} />
Expand Down
6 changes: 3 additions & 3 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import webpack from 'webpack';
import yargs from 'yargs';

const {optimizeMinimize} = yargs.alias('p', 'optimize-minimize').argv;
const { optimizeMinimize } = yargs.alias('p', 'optimize-minimize').argv;
const nodeEnv = optimizeMinimize ? 'production' : 'development';

export default {
Expand All @@ -16,7 +16,7 @@ export default {
},
module: {
loaders: [
{test: /\.js$/, loader: 'babel', exclude: /node_modules/}
{ test: /\.js$/, loader: 'babel', exclude: /node_modules/ }
]
},
externals: [
Expand All @@ -39,7 +39,7 @@ export default {
],
plugins: [
new webpack.DefinePlugin({
'process.env': {'NODE_ENV': JSON.stringify(nodeEnv)}
'process.env': { 'NODE_ENV': JSON.stringify(nodeEnv) }
})
],
devtool: optimizeMinimize ? 'source-map' : null
Expand Down
2 changes: 1 addition & 1 deletion webpack.test.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
},
module: {
loaders: [
{test: /\.js/, loader: 'babel', exclude: /node_modules/}
{ test: /\.js/, loader: 'babel', exclude: /node_modules/ }
]
},
devtool: 'inline-source-map'
Expand Down
8 changes: 4 additions & 4 deletions webpack.visual.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export default {
entry: './tests/visual',
module: {
loaders: [
{test: /\.js/, loader: 'babel', exclude: /node_modules/},
{test: /\.less$/, loader: 'style!css!less'},
{test: /\.woff|\.woff2$/, loader: 'url?prefix=font/&limit=5000'},
{test: /\.eot$|\.ttf$|\.svg$/, loader: 'file?prefix=font/'}
{ test: /\.js/, loader: 'babel', exclude: /node_modules/ },
{ test: /\.less$/, loader: 'style!css!less' },
{ test: /\.woff|\.woff2$/, loader: 'url?prefix=font/&limit=5000' },
{ test: /\.eot$|\.ttf$|\.svg$/, loader: 'file?prefix=font/' }
]
},
plugins: [
Expand Down

0 comments on commit 483a863

Please sign in to comment.