Skip to content

Instantly share code, notes, and snippets.

@squeedee
Created January 17, 2018 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squeedee/288c677f990dbe0aa052536a243fc92b to your computer and use it in GitHub Desktop.
Save squeedee/288c677f990dbe0aa052536a243fc92b to your computer and use it in GitHub Desktop.
Simple props based react router
<Router authorized={true}>
<Match fn={(props) => (props.authorized)}>
<Environments/>
</Match>
<Match fn={(props) => (!props.authorized)}>
<SlackPage/>
</Match>
</Router>
export const Match = ({children}) => (<React.Fragment>{children}</React.Fragment>)
class Router extends Component {
render() {
let newChildren = []
this.props.children.forEach(
(child) => {
if (child.props.fn(this.props)) {
newChildren.push(child)
}
}
)
return (<React.Fragment>{newChildren}</React.Fragment>)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment