Skip to content

Commit

Permalink
Add basePath prop
Browse files Browse the repository at this point in the history
- Allows specifying a base path for all paths in Switcher
  • Loading branch information
jdlehman committed Apr 25, 2015
1 parent a91e604 commit 862f5fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/switcheroo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions docs/components/Switcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ onChange(match, pathname) { ... }
### wrapper

If the `wrapper` prop is defined, the rendered `Switch` will be wrapped in the specified React component. Any additional props passed to the `Switcher` will also be properties of this component.

### basePath (default: '')

`basePath` is prepended to all path properties in the components inside `Switcher`. If `basePath` is set to `/base/path` then a component with path, `/home` will match the path `/base/path/home`.
8 changes: 5 additions & 3 deletions modules/components/Switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class Switcher extends Component {
getSwitch(path) {
var children = [].concat(this.props.children);
return children.filter((child) => {
return child.props.path === path;
return `${this.props.basePath}${child.props.path}` === path;
})[0];
}

Expand Down Expand Up @@ -97,12 +97,14 @@ Switcher.propTypes = {
defaultHandlerProps: React.PropTypes.object,
onChange: React.PropTypes.func,
wrapper: React.PropTypes.any,
location: React.PropTypes.string
location: React.PropTypes.string,
baseURL: React.PropTypes.string
};

Switcher.defaultProps = {
pushState: false,
hashChange: true,
load: true,
location: 'hash'
location: 'hash',
basePath: ''
};

0 comments on commit 862f5fd

Please sign in to comment.