Skip to content

Instantly share code, notes, and snippets.

@ooade
Created July 21, 2016 22:03
Show Gist options
  • Save ooade/40046c60e7858727cf34dc8aca80df35 to your computer and use it in GitHub Desktop.
Save ooade/40046c60e7858727cf34dc8aca80df35 to your computer and use it in GitHub Desktop.
Setup React Router
// Grab the react and react-dom pkgs -->
import React from 'react';
import ReactDOM from 'react-dom';
// Grab Router, Route and browserHistory from react-router ->
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
// Grab Navigation, signin and resource components -->
import Navigation from '../components/navigation';
import SignIn from '../components/signin';
import Resource from '../components/resource';
// Write an App Component -->
const App = (props) => {
return (
<div>
<Navigation />
{ props.children }
</div>
);
};
// Start Routes -->
const routes = (
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="/signin" component={SignIn} />
<Route path="/resource" component={Resource} />
</Route>
</Router>
);
// Render the App Component to the app class
// Use Meteor.startup (Makes sure the Meteor app starts up before you try rendering to the DOM)
Meteor.startup(() => {
ReactDOM.render(routes, document.querySelector('.app'));
});
import React from 'react';
export default() => {
return(
<div className="resource container">
Here's some resource you shouldn't be able to see as an unauthenticated user :p
</div>
);
};
import React from 'react';
export default() => {
return(
<div className="signin container">
<p>Click the SignIn button to continue...</p>
<button className="btn btn-success" onClick={ ()=> localStorage.setItem('auth', true) }>
Sign In
</button>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment