Skip to content

Commit

Permalink
Merge a378f00 into f0f87c1
Browse files Browse the repository at this point in the history
  • Loading branch information
killmenot committed Nov 2, 2016
2 parents f0f87c1 + a378f00 commit e9d9aaa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -18,7 +18,7 @@
"dependencies": {},
"peerDependencies": {
"react": ">=0.14.0",
"react-router": "^2.4.0"
"react-router": "^3.0.0"
},
"devDependencies": {
"eslint-config-jonnybuchanan": "3.2.1",
Expand All @@ -27,7 +27,7 @@
"react": "15.2.1",
"react-addons-test-utils": "15.2.1",
"react-dom": "15.2.1",
"react-router": "2.5.2",
"react-router": "3.0.0",

"bootstrap": "3.3.6"
},
Expand Down
20 changes: 18 additions & 2 deletions src/index.js
Expand Up @@ -13,6 +13,20 @@ function createLocationDescriptor({to, query, hash, state}) {
return {query, hash, state, ...to}
}

function omitProps(props, omittedPropNames) {
const isOmittedProp = {}
omittedPropNames.forEach(propName => { isOmittedProp[propName] = true })

const elementProps = {}
Object.entries(props).forEach(([propName, propValue]) => {
if (!isOmittedProp[propName]) {
elementProps[propName] = propValue
}
})

return elementProps
}

module.exports = function activeComponent(Component, options) {
if (!Component) {
throw new Error('activeComponent() must be given a tag name or React component')
Expand Down Expand Up @@ -73,10 +87,12 @@ module.exports = function activeComponent(Component, options) {
}
}

let componentProps = omitProps(props, ['params', 'location', 'routes'])

if (!link) {
return <Component {...props}>{this.props.children}</Component>
return <Component {...componentProps}>{this.props.children}</Component>
}
return <Component {...props}>
return <Component {...componentProps}>
<Link className={options.linkClassName} {...linkProps} to={location}>
{this.props.children}
</Link>
Expand Down

0 comments on commit e9d9aaa

Please sign in to comment.