Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React-router #32

Open
minaorangina opened this issue Mar 5, 2016 · 1 comment
Open

React-router #32

minaorangina opened this issue Mar 5, 2016 · 1 comment

Comments

@minaorangina
Copy link
Contributor

No description provided.

@sohilpandya
Copy link

React Router Tutorial

Installation Steps

  • Install React Router npm i react-router --save

Navigate to app.js or route js file

import {Router, Route, hashHistory} from 'react-router' //es6
var Router = require('react-router').Router //es5
var Route = require('react-router').Route //es5
var hashHistory = require('react-router').hashHistory //es5

Inside the app.js render method, replace your exisiting component with the Router component as such:-

  <Router history={hashHistory}>
    <Route path="/" component={App}/>
  </Router>

Add another Route

Add additional components for which you want to add routes for

about.jsx
contact.jsx
<Route path="/about" component={about}/>
<Route path="/contact" component={contact}/>

Now visit hostname:3000/#/about & hostname:3000/#/contact to view the additional paths

Navigate with Link

Add a link to an element

import {Link} from 'react-router' //es6
var Link = require('react-router').Link //es5

Now add a link element to link to a route

<h2><Link to="/about">About</Link><h2>

Your h2 tag will now navigate you to About component

*###### You cannot pass down a string, you have to pass an object with pathname as found in example: - http://stackoverflow.com/questions/30115324/pass-props-in-link-react-router

Nested Routes

minaorangina added a commit that referenced this issue Mar 5, 2016
installs react router and documents problem with link #32
heron2014 pushed a commit that referenced this issue Mar 5, 2016
added router and the link to the button see #32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants