REACT JS TUTORIAL #7 - React Router Params & Queries
Skills:
React90%
Key Takeaways
Implements React Router with params and queries for single page apps using React JS
Full Transcript
so before I get into handling complicated data with react that would be flux or Redux which I'm really excited to get into uh let's go ahead and just cover a little bit more on routing handling routes handling route information and then let's get this HTML if you'll remember right now the entire HTML is just rendering into this so we want to get almost all this HTML into our actual react single page app so we'll want to convert that all as well once those two are out of the way we're ready to start taking on a a framework style approach to react um and that's really where react gets fun really starts give you some great mental patterns uh so let's look at uh some more routing features right now lots of times say with archives you'll actually let me go back to my page lot times you want to go archives SL some article or say some article some filter you know you'll actually want to go to a specific archive so the easy way to do this is to um don't don't want to save my web page easiest way to do this is just add another route or more detail to my route so we're going to go to archives and we're going to go to specific article and that'll be called article so I'm adding what's uh called a Pam now to my URL so let's go and do that let's refresh so now I got archives which no longer matches that's very important to know now this path is this route is only going to match archives article so that's going to be a specific article um and now it's going to match archives SL some article let's go ahead and look at this archives let's go ahead console log props now so I'm in the archives route again which is whenever we go archives and give it an article it's going to render the archives component so in this archives component let's go ahead and inspect these props now uh you can see that it's passing a pams and article has a value so it's some article some other article let's go look at it now rendered article is some other article excellent let's actually go spit this out on the page here there we go this props H sorry not props pams and I'll clean that up in a second so there you go some other article some other you know it's basically going to change as my as my path changes so that's cool um and the way you could really clean that up is you'd go const uh pams equals this props and then I can just go pam. article that cleans it up a different bit a difference or if if you were pulling multiple pams and then you're pulling multiple values out of those pams you could even clean up more so then this could just be article you know for if you're if you're adding a lot of values to your render method it really helps to have nice clean small variable names U so there we go that's rendered in uh another thing you can do without any configuration on your route is just you can just use Query variables so we can just add a question mark and let's go say date equals today and now if I look at again my props object I can look at the location and I've got this query in there and that's just real time going to be any of your query brand values date today and filter equals none so then I can go back to location I've got date today filter none so let's go ahead and snatch that pull that in cons query equals pulling query out of location and then let's go ahead and get what did I Ed date and filter so then let's uh wrap this in a div since I can't return just three H1s and then let's actually spit out date filter and there we go now I'm snatching all my information that the user might be passing in there date today filter none and then if I were to say filter all there you go it's all going to change real time yesterday blah blah blah um and then lastly you can also make stuff uh you can make stuff optional so I can go to archives and I can actually just wrap these in parns and now it will match if I do article or if I don't have article in there so that's probably more what I want the archives page to be doing so that's how you do that let's go and take this archives link now uh the last thing I want to show you in this video is lots of times you want to know if your route is active you want to add a class like up here if the featured route was active I'd want this to have the class. active for all my bootstrap stuff to look good uh so that's very simple to do with react router let me go to my layout yep here we go so you're simply just going to add active class name as long as you're using the link component you simply just go active class name equals and then whatever you want that to be so in this case I've added active class name equals test so whenever settings is let's go ahead inspect this archives element I do not have a class name of test but when the archives route is there Boom the active class of test just got added and again it's gone so that's kind of really nice and then if you wanted to do it programmatically programmatically um then you can actually get this out of History so if you remember I always have that props history right there you can see so let's get history out out of props and then you can go history do isactive and we'll just look up we'll just look up archives let's console log this so we're going to console log if archives is active let's say so false true false true there you go so now um everything's working we can go ahead and just pull our components in I'm not going to bore you by doing this in front of you uh but I'm just going to go ahead and take the navigation out put it into layout as a navigation components uh get the footer out into its own stuff basically just get all this stuff broken out into layout and then from here on out we're going to cover flux and Redux and data and a whole bunch of fun stuff so at this point get comfortable with how react Works get comfortable with how routing works you want to know those well before you get into the framework aspect of react so once those are good to go check out the next videos
Original Description
React Router has great and simple features for accessing route params and query params. Let's get into them.
GET THE SOURCE CODE:
https://github.com/learncodeacademy/react-js-tutorials
React JS #1: Intro & Workspace Setup
https://youtu.be/MhkGQAoc7bc (Coming Tues, Feb 2@11CST)
React JS #2: Anatomy of a Component
https://youtu.be/fd2Cayhez58 (Coming Wed, Feb 3@11CST)
React JS #3: Composing Multiple Components
https://youtu.be/vu_rIMPROoQ (Coming Thurs, Feb 4@11CST)
React JS #4: State, Props & Data
https://youtu.be/qh3dYM6Keuw (Coming Fri, Feb 5@11CST)
React JS #5: Events & Data Changes
https://youtu.be/_D1JGNidMr4 (Coming Mon, Feb 8@11CST)
React JS #6: React Router & Intro to Single Page Apps
https://youtu.be/olLI54FATb8 (Coming Tues, Feb 9@11CST)
React JS #7: React Router Params & Queries
https://youtu.be/ZBxMljq9GSE
React JS #8 - React Inline Styles & Component Arrays
https://youtu.be/XVdwq8W2ZsM
-~-~~-~~~-~~-~-
Also watch: "Responsive Design Tutorial - Tips for making web sites look great on any device"
https://www.youtube.com/watch?v=fgOO9YUFlGI
-~-~~-~~~-~~-~-
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from LearnCode.academy · LearnCode.academy · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Web Development Tutorial for Beginners (#1) - How to build webpages with HTML, CSS, Javascript
LearnCode.academy
Web Development Tutorial for Beginners (#2) - Basic CSS - How to build a website with HTML & CSS
LearnCode.academy
How to create CSS Layouts - Web Development Tutorial for Beginners (#3) - with HTML & CSS
LearnCode.academy
Bootstrap Tutorial For Beginners - Responsive Design with Bootstrap 3 - Responsive HTML, CSS
LearnCode.academy
Angularjs Tutorial for Beginners - learn Angular.js using UI-Router
LearnCode.academy
CSS Tutorial - Web Development Tutorial for Beginners (#5)
LearnCode.academy
Node.js tutorial for beginners - an introduction to Node.js with Express.js
LearnCode.academy
Github Tutorial For Beginners - Github Basics for Mac or Windows & Source Control Basics
LearnCode.academy
Javascript Tutorial - Programming Tutorial for Beginners Pt 1
LearnCode.academy
Javascript Tutorial - jQuery Tutorial for Beginners Pt 2
LearnCode.academy
AngularJS Directives Tutorial - Part 1 - Demystifying Angular Directives
LearnCode.academy
WATCH THIS IF YOU WANT TO BECOME A WEB DEVELOPER! - Web Development Career advice
LearnCode.academy
YEOMAN TUTORIAL - Master Front-End Workflow with Yeoman, Grunt and Bower
LearnCode.academy
BOWER! - Streamline Web Workflow with Bower Package Manager
LearnCode.academy
Chrome DevTools for CSS - Better CSS Coding & CSS Debugging with Developer Tools
LearnCode.academy
GITHUB ATOM - Why Atom.io will be your favorite Text Editor!
LearnCode.academy
GITHUB PULL REQUEST, Branching, Merging & Team Workflow
LearnCode.academy
Pimp that Terminal - Add shortcuts and functions to your .bash_profile to simplify routine tasks
LearnCode.academy
jQuery Tutorial #3 - Writing Smarter, Better Code - jQuery Tutorial for Beginners
LearnCode.academy
jQuery Tutorial #2 - Event Binding - jQuery Tutorial for Beginners
LearnCode.academy
jQuery Tutorial #1 - jQuery Tutorial for Beginners
LearnCode.academy
Node.js MongoDB Tutorial using Mongoose
LearnCode.academy
Node.js tutorial for beginners 2014 - an introduction to Node.js with Express.js
LearnCode.academy
WEB DEVELOPMENT - SECRETS TO STARTING A CAREER in the Web Development Industry
LearnCode.academy
jQuery Tutorial #4 - DOM Traversal with jQuery
LearnCode.academy
jQuery Tutorial #5 - Building a jQuery Tab Panel Widget
LearnCode.academy
jQuery Tutorial #6 - Building a jQuery Image Slider
LearnCode.academy
jQuery Ajax Tutorial #1 - Using AJAX & API's (jQuery Tutorial #7)
LearnCode.academy
jQuery Ajax Tutorial #2 - Posting data to backend (jQuery tutorial #8)
LearnCode.academy
jQuery Ajax Tutorial #3 - Delegating Events & Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
jQuery Ajax Tutorial #4 - "Edit" modes & Better Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
How to put your website online - how to FTP to a domain & upload files to a webhost
LearnCode.academy
Basic Terminal Usage - Cheat Sheet to make the command line EASY
LearnCode.academy
SSH Tutorial - Basic server administration with SSH
LearnCode.academy
Vagrant Tutorial - Running a VM For Your Local Development Environment
LearnCode.academy
Sublime Text Favorite Packages and Workflow
LearnCode.academy
What Makes Javascript Weird...and AWESOME - Pt 1
LearnCode.academy
Javascript is Event-Driven - What makes Javascript Weird...and Awesome Pt 2
LearnCode.academy
Javascript Closures Tutorial - What makes Javascript Weird...and Awesome Pt 3
LearnCode.academy
FREE REST API - Practice Developing Javascript AJAX Apps with this API
LearnCode.academy
Javascript Scope Tutorial - What Makes Javascript Weird...and Awesome Pt 4
LearnCode.academy
Javascript Context Tutorial - What makes Javascript Weird...and Awesome Pt5
LearnCode.academy
Nginx Tutorial - Proxy to Express Application, Load Balancer, Static Cache Files
LearnCode.academy
Live Reload Sublime, Chrome, Anything - Fast and easy with Live-Server
LearnCode.academy
Are you bad, good, better or best with Async JS? JS Tutorial: Callbacks, Promises, Generators
LearnCode.academy
Javascript Generators - THEY CHANGE EVERYTHING - ES6 Generators Harmony Generators
LearnCode.academy
Web Development Advice - Interview with Dev Tips
LearnCode.academy
How the Internet Works for Developers - Pt 2 - Servers & Scaling
LearnCode.academy
How the Internet Works for Developers - Pt 1 - Overview & Frontend
LearnCode.academy
HAPROXY vs NGINX - 10,000 requests while killing servers
LearnCode.academy
Node.js Cluster - Boost Node App Performance & Stability with Clustering
LearnCode.academy
Web Dev Training with Treehouse
LearnCode.academy
What is Node.js Exactly? - a beginners introduction to Nodejs
LearnCode.academy
How to deploy node.js applications #1 - spin up a server
LearnCode.academy
Deploying node.js applications #2 - provision server & setup flightplan
LearnCode.academy
Deploying Node.js Applications - Deploy Node the right way - as an Upstart Service
LearnCode.academy
Mobile Web Design - Coding Workflow For Mobile Websites
LearnCode.academy
WHY YOU NEED A BUILD SYSTEM LIKE GRUNT, GULP, BRUNCH FOR YOUR WEBSITE
LearnCode.academy
GRUNT TUTORIAL - Grunt makes your web development better!
LearnCode.academy
STOP USING FTP! - How to Deploy with Flightplan over SSH
LearnCode.academy
More on: React
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Medium · JavaScript
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · Programming
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · JavaScript
The US Frontend Engineer Market in 2026: A Data-Driven Reality Check (and the Bias That Stops Us Seeing It)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI