Created
March 18, 2018 19:47
-
-
Save dvrajan/580f004e726bdeddc4e89668f66f4717 to your computer and use it in GitHub Desktop.
Blogpost sample Router.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import Component1 from "./components/Component1"; | |
import Component2 from "./components/Component2"; | |
class Router { | |
constructor(registry = {}) { | |
this._registry = registry; | |
} | |
route(routingKey, props) { | |
Component = this._registry[routingKey] | |
return <Component {...props} /> | |
} | |
} | |
router = new Router({ | |
Key1: Component1, | |
Key2: Component2 | |
}); | |
export default router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment