SlideShare a Scribd company logo
1 of 12
Download to read offline
Front End Workshops
React Router
Mario García Martín
mgarcia@visual-engin.com
React Router
Client side navigation
Introduction
Inspired by Ember.js router
React-router
React
History
How does a router work?
*See alternative data management libraries at https://github.com/facebook/react/wiki/Complementary-Tools#model-management
*See alternative routing libraries at https://github.com/facebook/react/wiki/Complementary-Tools#routing
Histories
A history knows how to listen to the browser’s address bar for changes
Different flavors are available...
...but you can build your custom history (if you dare)!
http://example.com/some/path
http://example.com/#/some/path
browserHistory
createMemoryHistory
hashHistory
Routing basics (1 of 2)
ReactDOM.render(
<App />,
document.querySelector('.container')
);
From... to...
ReactDOM.render(
<Router history={browserHistory}>
<Route path="/" component={App} />
</Router>,
document.querySelector('.container')
);
ReactDOM.render(
<Router history={browserHistory}>
<Route path="/" component={App} />
<Route path="/about" component={About} />
<Route path="/contact" component={Contact} />
<Route path="*" component={NotFound} />
</Router>,
document.querySelector('.container')
);
A more practical example...
Routing basics (2 of 2)
Same example using the routes prop...
import routes from './routes';
ReactDOM.render(
<Router history={browserHistory} routes={routes} />,
document.querySelector('.container')
);
// routes.js
export default (
<Route path="/" component={App} />
<Route path="/about" component={About} />
<Route path="/contact" component={Contact} />
<Route path="*" component={NotFound} />
);
A more scalable way of specifying the routes
*For more advanced usage, see https://github.com/reactjs/react-router/blob/master/docs/guides/DynamicRouting.md
Route nesting
ReactDOM.render(
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={Home} />
<Redirect from="home" to="/" />
<Route path="contact" component={Contact} />
<Route path="*" component={NotFound} />
</Route>
</Router>,
document.querySelector('.container')
);
/
App
Home
Don’t forget to
render the children
components inside
their parent!
/home
App
Home
/contact
App
Contact
/random
App
NotFound
{this.props.children}
Dynamic routing
In the component you can use this.props.params.<param_name>
In the route you can define dynamic segments
In the component you can use this.props.params.<param_name>
Define an optional param by wrapping it between parenthesis
<Route path="/users/:userId" component={UserItem} />
<Route path="/contact(/:mode)" component={Contact} />
Navigation links
Link
<Link to="/contact">Contact us</Link>
In the component you can use this.props.location.query.<param_name>
Query params
<Link to={"/users/" + user.id} activeStyle={{ color: red }}>User details</Link>
<Link to={"/users/" + user.id} activeClassName="active">User details</Link>
IndexLink
<IndexLink to="/">Contact us</IndexLink>
<Link to={{ pathname: "/user/bob", query: { showAge: true } }}>Bob</Link>
Navigation within components
The router instance can be made accessible through the contextTypes
class CoolButton extends Component {
static contextTypes = { router: PropTypes.object };
onButtonClick() {
this.context.router.push('/cool');
}
render() {
return <button onClick={this.onButtonClick.bind(this)}>Navigate</button>;
}
}
Invoke router push(‘<target_url>’) or replace(‘<target_url>’)
methods to navigate programmatically
Not the recommended way since react-router 2.4.0*
*See https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#changes-to-thiscontext
Thanks for your time!
Do you have any questions?
Workshop 21: React Router

More Related Content

What's hot

What's hot (20)

State management in react applications (Statecharts)
State management in react applications (Statecharts)State management in react applications (Statecharts)
State management in react applications (Statecharts)
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjs
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
 
React workshop
React workshopReact workshop
React workshop
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 
Reactjs
ReactjsReactjs
Reactjs
 
ReactJS
ReactJSReactJS
ReactJS
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
React JS
React JSReact JS
React JS
 
react redux.pdf
react redux.pdfreact redux.pdf
react redux.pdf
 

Viewers also liked

Viewers also liked (11)

Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Webpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ StepsWebpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ Steps
 
Game of Frameworks - GDG Cáceres #CodeCC
Game of Frameworks - GDG Cáceres #CodeCCGame of Frameworks - GDG Cáceres #CodeCC
Game of Frameworks - GDG Cáceres #CodeCC
 
Workshop 24: React Native Introduction
Workshop 24: React Native IntroductionWorkshop 24: React Native Introduction
Workshop 24: React Native Introduction
 
Workhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de SwiftWorkhop iOS 1: Fundamentos de Swift
Workhop iOS 1: Fundamentos de Swift
 
Workshop 25: React Native - Components
Workshop 25: React Native - ComponentsWorkshop 25: React Native - Components
Workshop 25: React Native - Components
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 
Workshop iOS 2: Swift - Structures
Workshop iOS 2: Swift - StructuresWorkshop iOS 2: Swift - Structures
Workshop iOS 2: Swift - Structures
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit Testing
 

Similar to Workshop 21: React Router

Similar to Workshop 21: React Router (20)

URL Design
URL DesignURL Design
URL Design
 
Reitit - Clojure/North 2019
Reitit - Clojure/North 2019Reitit - Clojure/North 2019
Reitit - Clojure/North 2019
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
Large Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and FriendsLarge Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and Friends
 
Large Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and FriendsLarge Scale Crawling with Apache Nutch and Friends
Large Scale Crawling with Apache Nutch and Friends
 
Search Engine Spiders
Search Engine SpidersSearch Engine Spiders
Search Engine Spiders
 
OSS NA 2019 - Demo Booth deck overview of Egeria
OSS NA 2019 - Demo Booth deck overview of EgeriaOSS NA 2019 - Demo Booth deck overview of Egeria
OSS NA 2019 - Demo Booth deck overview of Egeria
 
6 10-presentation
6 10-presentation6 10-presentation
6 10-presentation
 
REST and some Python (or 'Python "sinners" must REST')
REST and some Python (or 'Python "sinners" must REST')REST and some Python (or 'Python "sinners" must REST')
REST and some Python (or 'Python "sinners" must REST')
 
Codeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate UriCodeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate Uri
 
RESTful Web Applications with Apache Sling
RESTful Web Applications with Apache SlingRESTful Web Applications with Apache Sling
RESTful Web Applications with Apache Sling
 
Web Applications Development
Web Applications DevelopmentWeb Applications Development
Web Applications Development
 
Academy PRO: Node.js default stack. Lecture 2
Academy PRO: Node.js default stack. Lecture 2Academy PRO: Node.js default stack. Lecture 2
Academy PRO: Node.js default stack. Lecture 2
 
Sinatra
SinatraSinatra
Sinatra
 
Bootstrap rails-app
Bootstrap rails-appBootstrap rails-app
Bootstrap rails-app
 
sMash at May NYPHP UG
sMash at May NYPHP UGsMash at May NYPHP UG
sMash at May NYPHP UG
 
Flashcamp
FlashcampFlashcamp
Flashcamp
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
Improving Human–Semantic Web Interaction: The Rhizomer Experience
Improving Human–Semantic Web Interaction: The Rhizomer ExperienceImproving Human–Semantic Web Interaction: The Rhizomer Experience
Improving Human–Semantic Web Interaction: The Rhizomer Experience
 

More from Visual Engineering

More from Visual Engineering (20)

Workshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSWorkshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJS
 
Workshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operatorsWorkshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operators
 
Workshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensionesWorkshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensiones
 
Workshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux AdvancedWorkshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux Advanced
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS Introduction
 
Workshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effectsWorkshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effects
 
Workshop 17: EmberJS parte II
Workshop 17: EmberJS parte IIWorkshop 17: EmberJS parte II
Workshop 17: EmberJS parte II
 
Workshop 16: EmberJS Parte I
Workshop 16: EmberJS Parte IWorkshop 16: EmberJS Parte I
Workshop 16: EmberJS Parte I
 
Workshop 15: Ionic framework
Workshop 15: Ionic frameworkWorkshop 15: Ionic framework
Workshop 15: Ionic framework
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Workshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSWorkshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJS
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
Workshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototypingWorkshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototyping
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Workshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVCWorkshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVC
 
Workshop 7: Single Page Applications
Workshop 7: Single Page ApplicationsWorkshop 7: Single Page Applications
Workshop 7: Single Page Applications
 
Workshop 6: Designer tools
Workshop 6: Designer toolsWorkshop 6: Designer tools
Workshop 6: Designer tools
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 

Workshop 21: React Router

  • 1. Front End Workshops React Router Mario García Martín mgarcia@visual-engin.com
  • 3. Introduction Inspired by Ember.js router React-router React History How does a router work? *See alternative data management libraries at https://github.com/facebook/react/wiki/Complementary-Tools#model-management *See alternative routing libraries at https://github.com/facebook/react/wiki/Complementary-Tools#routing
  • 4. Histories A history knows how to listen to the browser’s address bar for changes Different flavors are available... ...but you can build your custom history (if you dare)! http://example.com/some/path http://example.com/#/some/path browserHistory createMemoryHistory hashHistory
  • 5. Routing basics (1 of 2) ReactDOM.render( <App />, document.querySelector('.container') ); From... to... ReactDOM.render( <Router history={browserHistory}> <Route path="/" component={App} /> </Router>, document.querySelector('.container') ); ReactDOM.render( <Router history={browserHistory}> <Route path="/" component={App} /> <Route path="/about" component={About} /> <Route path="/contact" component={Contact} /> <Route path="*" component={NotFound} /> </Router>, document.querySelector('.container') ); A more practical example...
  • 6. Routing basics (2 of 2) Same example using the routes prop... import routes from './routes'; ReactDOM.render( <Router history={browserHistory} routes={routes} />, document.querySelector('.container') ); // routes.js export default ( <Route path="/" component={App} /> <Route path="/about" component={About} /> <Route path="/contact" component={Contact} /> <Route path="*" component={NotFound} /> ); A more scalable way of specifying the routes *For more advanced usage, see https://github.com/reactjs/react-router/blob/master/docs/guides/DynamicRouting.md
  • 7. Route nesting ReactDOM.render( <Router history={browserHistory}> <Route path="/" component={App}> <IndexRoute component={Home} /> <Redirect from="home" to="/" /> <Route path="contact" component={Contact} /> <Route path="*" component={NotFound} /> </Route> </Router>, document.querySelector('.container') ); / App Home Don’t forget to render the children components inside their parent! /home App Home /contact App Contact /random App NotFound {this.props.children}
  • 8. Dynamic routing In the component you can use this.props.params.<param_name> In the route you can define dynamic segments In the component you can use this.props.params.<param_name> Define an optional param by wrapping it between parenthesis <Route path="/users/:userId" component={UserItem} /> <Route path="/contact(/:mode)" component={Contact} />
  • 9. Navigation links Link <Link to="/contact">Contact us</Link> In the component you can use this.props.location.query.<param_name> Query params <Link to={"/users/" + user.id} activeStyle={{ color: red }}>User details</Link> <Link to={"/users/" + user.id} activeClassName="active">User details</Link> IndexLink <IndexLink to="/">Contact us</IndexLink> <Link to={{ pathname: "/user/bob", query: { showAge: true } }}>Bob</Link>
  • 10. Navigation within components The router instance can be made accessible through the contextTypes class CoolButton extends Component { static contextTypes = { router: PropTypes.object }; onButtonClick() { this.context.router.push('/cool'); } render() { return <button onClick={this.onButtonClick.bind(this)}>Navigate</button>; } } Invoke router push(‘<target_url>’) or replace(‘<target_url>’) methods to navigate programmatically Not the recommended way since react-router 2.4.0* *See https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#changes-to-thiscontext
  • 11. Thanks for your time! Do you have any questions?