Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,870 --> 00:00:07,620
It's time to finally start making our application actually navigate to different pages so there will
2
00:00:07,620 --> 00:00:16,010
then be able to start actually building each page and adding content to handle navigation in our application.
3
00:00:16,010 --> 00:00:25,130
I use the popular react router library and since this is the most popular library for navigation in
4
00:00:25,130 --> 00:00:30,140
react and I do already expect you to already have react experience.
5
00:00:30,140 --> 00:00:36,830
I'm expecting that you have some familiarity with react router or at least understand the concept of
6
00:00:36,830 --> 00:00:45,540
how it works so I'm not going to dive into all of the ins and outs but I am going to obviously completely
7
00:00:45,540 --> 00:00:53,800
walk you through setting it up in this application I'll attach a link to the official react router documentation
8
00:00:53,800 --> 00:01:00,760
to this lecture so that if at the end of the video you still are feeling shaky on react router you can
9
00:01:00,760 --> 00:01:07,450
go ahead and read there for more information but I think that the general concepts are pretty simple
10
00:01:07,750 --> 00:01:12,430
and you shouldn't have that hard of a time following along all right.
11
00:01:12,460 --> 00:01:20,680
So here we are in the project directory in my code editor and I want to go over to our app dot J.S.
12
00:01:20,680 --> 00:01:30,120
file this is where we will set up the routing for our application we'll start by right here importing
13
00:01:30,750 --> 00:01:46,690
browser router route and switch all from react react router Dom make sure you get the last part DRM
14
00:01:46,810 --> 00:01:56,960
on their then inside of our theme provider we're going to open up our browser router and we're going
15
00:01:56,960 --> 00:02:03,520
to move our header inside of there and now we can actually get rid of our little Hello.
16
00:02:03,530 --> 00:02:04,220
Finally.
17
00:02:04,220 --> 00:02:12,440
So say goodbye to our hello and underneath the header is where we're going to switch over all of our
18
00:02:12,440 --> 00:02:22,160
different routes these switch component only renders the first component which matches the given route
19
00:02:22,370 --> 00:02:29,000
whereas if we just put all of our routes inside of the router there's a possibility that two different
20
00:02:29,000 --> 00:02:36,200
routes could both match the U.R.L. and we could have two different pages rendered on the screen at once
21
00:02:37,150 --> 00:02:45,930
this obviously is not ideal and so we use these switch component the browser router component simply
22
00:02:45,930 --> 00:02:53,610
handles the functionality necessary for providing the browser with the correct you are Rel for each
23
00:02:53,610 --> 00:03:02,790
page navigated to as well as manipulating the history object and enabling navigation via the Forward
24
00:03:02,820 --> 00:03:09,840
and back buttons on the page those are the forward and backward buttons in the browser which would not
25
00:03:09,840 --> 00:03:18,530
work without the browser router so inside of our switch we're going to place our first route component
26
00:03:18,920 --> 00:03:27,350
and this is going to have a few different properties on it the first property is exact and so that's
27
00:03:27,350 --> 00:03:33,110
going to default to true since we're not going to put any other options on it and that just ensures
28
00:03:33,140 --> 00:03:39,470
that this rule will only be rendered if the exact you are specified is provided.
29
00:03:39,470 --> 00:03:46,070
So anything else that could possibly match it we really don't want to render unless we know specifically
30
00:03:46,310 --> 00:03:55,400
exactly that the user is trying to access this page then we need our path prop and we're going to set
31
00:03:55,430 --> 00:04:03,820
this equal to the path in the browser that we want to be displayed for example our home screen is a
32
00:04:03,820 --> 00:04:13,960
path of simply slash after the path we add the last property which is component and we are going to
33
00:04:13,990 --> 00:04:22,170
set this equal to the brackets and inside of here you place the component that you want to be rendered.
34
00:04:22,180 --> 00:04:29,800
When this route is accessed eventually we're going to go in and have a different component for each
35
00:04:29,800 --> 00:04:33,490
page that we will pass in to be rendered here.
36
00:04:33,490 --> 00:04:39,970
But for now I just want to put in a dummy component that's just going to put something on the screen
37
00:04:40,000 --> 00:04:46,760
so that we can tell whether or not we're actually navigating we'll do that by creating an arrow function
38
00:04:46,910 --> 00:04:54,560
which simply is going to return a div with home inside of it.
39
00:04:55,600 --> 00:05:04,180
So then if we go and we close up our route and we hit save we see the screen refresh and now we have
40
00:05:04,180 --> 00:05:07,470
home displayed on the screen instead of the previous.
41
00:05:07,480 --> 00:05:09,050
Hello.
42
00:05:09,070 --> 00:05:15,640
Let's go in and copy this route component and we're going to add one for all of the different routes
43
00:05:15,700 --> 00:05:17,850
in our application.
44
00:05:17,990 --> 00:05:20,230
That means we're going to need eight more.
45
00:05:20,240 --> 00:05:26,360
So one two three four five six seven eight.
46
00:05:26,480 --> 00:05:34,160
And now we need to go in and specify the path for each one as well as change the text inside the component
47
00:05:34,190 --> 00:05:37,800
that's rendered so that we can fully test our navigation.
48
00:05:38,210 --> 00:05:52,350
So let's set a path for this one of services here of custom software below that mobile apps below here.
49
00:05:52,360 --> 00:06:09,240
Web sites then revolution then slash about slash contact and at the very bottom slash estimate will
50
00:06:09,240 --> 00:06:14,480
now go through and change the text to reflect each of those pages as well.
51
00:06:14,970 --> 00:06:29,490
So here we'll put the services and then custom software then mobile apps down here and then web science
52
00:06:31,560 --> 00:06:48,700
the Rev though Lucian about us contact us and estimate let's save this and our page will refresh.
53
00:06:48,740 --> 00:06:56,890
And now if we come over to the browser and try to go to a different tab Oh well you see that it changes
54
00:06:56,890 --> 00:06:59,500
the styling for the active tab up here.
55
00:06:59,500 --> 00:07:04,510
But we're still seeing just the home text displayed on the screen.
56
00:07:04,550 --> 00:07:10,160
Well that's because we haven't actually set up our tabs to change the route.
57
00:07:10,160 --> 00:07:17,780
So let's go ahead and now move over into our header dot J.S. file and start by at the top here.
58
00:07:17,810 --> 00:07:29,190
Let's import and then we will D structure this a link from react if I can get that right.
59
00:07:29,190 --> 00:07:39,050
React router Dom then if you remember from the documentation we're going to pass that link and all of
60
00:07:39,050 --> 00:07:47,840
its properties to each of these tabs using the component prop. So if we continue down to each of our
61
00:07:47,840 --> 00:08:00,370
tabs and after the class name we go ahead and we add component equals brackets link this now turns our
62
00:08:00,370 --> 00:08:09,340
material UI tab into a react router link components while still maintaining all of the correct styling
63
00:08:09,370 --> 00:08:11,350
and functionality.
64
00:08:11,490 --> 00:08:19,260
Let's go ahead and copy that component equals link and we're going to add that on to each of the tabs
65
00:08:19,530 --> 00:08:27,640
but be sure to make sure you are putting in the right place for each one and then hit save.
66
00:08:27,690 --> 00:08:32,730
We still actually have one last thing to do before it's totally working and that is to actually now
67
00:08:32,730 --> 00:08:41,690
tell those link components where they need to go so for each component or tab rather we'll start after
68
00:08:41,690 --> 00:08:49,820
the component equals link property and we will add a another property called two and set that equal
69
00:08:49,820 --> 00:08:56,830
to a string and that string is the path to the route that we specified in app dot.
70
00:08:56,830 --> 00:08:57,860
J Yes.
71
00:08:57,890 --> 00:09:05,660
So if you look back here and you look at all of the paths that we specified so we need to reference
72
00:09:05,660 --> 00:09:16,090
these paths here on our tab links to tell them which page to navigate to this to prop is actually a
73
00:09:16,090 --> 00:09:18,460
prop of the link component.
74
00:09:18,460 --> 00:09:26,620
But as I explained before all properties they are not used by the tab component are passed down to the
75
00:09:26,620 --> 00:09:33,190
link component things to this component composition from material UI.
76
00:09:33,580 --> 00:09:38,920
So we can just put our two property here and it will be passed down as if we put it directly on the
77
00:09:38,920 --> 00:09:47,090
link like normal and we will specify this first one as a link to our just slash page.
78
00:09:47,080 --> 00:09:55,480
We can go ahead and copy that and now we'll put a two onto every other tab except we need to change
79
00:09:55,540 --> 00:10:15,930
the path to now slash services and here to revolution and here to about abound and here to slash contact
80
00:10:17,260 --> 00:10:19,360
if we go ahead and save this.
81
00:10:19,360 --> 00:10:28,580
Now once the page refreshes we can go over and if we try and select a new tab Oh something's wrong here
82
00:10:28,910 --> 00:10:32,130
it looks like I misspelled the services.
83
00:10:32,180 --> 00:10:34,870
So let's go to.
84
00:10:35,180 --> 00:10:42,830
Right here you'll probably notice that services will save and the page refreshed still on the wrong
85
00:10:42,830 --> 00:10:43,370
your url.
86
00:10:43,370 --> 00:10:46,460
So let's go back to the home page we see home.
87
00:10:46,520 --> 00:10:47,900
Let's go to services.
88
00:10:47,900 --> 00:10:56,810
We see services the revolution about and contact and so now not only is the active tab being managed
89
00:10:56,810 --> 00:11:04,100
and highlighted but we are actually rendering different content for each page as well as changing the
90
00:11:04,100 --> 00:11:13,200
U.R.L. for each tab that we are on so that is basically all of the functionality for navigation that
91
00:11:13,200 --> 00:11:17,640
we need in our application now fully wired up and working.
92
00:11:17,970 --> 00:11:24,740
So if we just refresh the page oh do you see that look at the home.
93
00:11:24,780 --> 00:11:28,200
It says we are on slash revolution.
94
00:11:28,200 --> 00:11:35,930
The content is displayed the revolution but the active tab says that we are on the home page.
95
00:11:36,180 --> 00:11:43,560
So it looks like whenever we are refreshing the page it's going to default back to that home page no
96
00:11:43,560 --> 00:11:46,550
matter which one we're actually on.
97
00:11:46,560 --> 00:11:52,590
So to take a look at what is going on here and how we can fix it let's go to the next video.
11733
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.