Skip to content

Instantly share code, notes, and snippets.

@dvrajan
Created March 18, 2018 19:47
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 dvrajan/580f004e726bdeddc4e89668f66f4717 to your computer and use it in GitHub Desktop.
Save dvrajan/580f004e726bdeddc4e89668f66f4717 to your computer and use it in GitHub Desktop.
Blogpost sample Router.js
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