Created
October 7, 2016 00:43
-
-
Save terrierscript/4d97312fda702359c1eb24a00cae67cd to your computer and use it in GitHub Desktop.
react-router@v4 Wizard
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, { Component, PropTypes } from 'react' | |
| import Router from 'react-router/BrowserRouter' | |
| import { Match, Link, Redirect } from 'react-router' | |
| const First = () => <div>First</div> | |
| const Second = () => <div>Second</div> | |
| const Third = () => <div>Third</div> | |
| const wizardLink = (pathname) => { | |
| switch(pathname){ | |
| case '/': | |
| return '/2' | |
| case '/2': | |
| return '/3' | |
| } | |
| return '/' | |
| } | |
| const Navigation = (props) => { | |
| console.log(props) | |
| const nextTo = wizardLink(props.pathname) | |
| return <Link to={nextTo}>next</Link> | |
| } | |
| export default () => { | |
| return <Router> | |
| <div> | |
| {/* components */} | |
| <Match pattern="/" exactly component={First} /> | |
| <Match pattern="/2" exactly component={Second} /> | |
| <Match pattern="/3" exactly component={Third} /> | |
| {/* navigation */} | |
| <Match pattern="/*" component={Navigation} /> | |
| </div> | |
| </Router> | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment