You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-1Lines changed: 60 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,4 +52,63 @@ ReactDOM.render(
52
52
document.getElementById('root'));
53
53
```
54
54
55
-
The goal for Hash Router is to keep our user interface in sync with what ther URL is. Meaning, that will display specific components on what the URL in our browser is.
55
+
The goal for Hash Router is to keep our user interface in sync with what ther URL is. Meaning, that will display specific components on what the URL in our browser is.
56
+
57
+
### Route
58
+
59
+
Route is the component we will use from `react-router-dom` to determine a specific route for what component will be displayed based on the URL.
60
+
61
+
We first need to import it into our file to use.
62
+
63
+
```js
64
+
import {Route} from'react-router-dom';
65
+
```
66
+
67
+
> Make sure to use object destructering!
68
+
69
+
We can now use `Route` inside of our JSX and give it specific props to determine what component is displayed based off of the URL path.
70
+
71
+
```js
72
+
<Route />
73
+
```
74
+
75
+
#### Component
76
+
77
+
The `component` prop is the prop we can add to determine what component is displayed.
78
+
79
+
```js
80
+
<Route component={Home} />
81
+
```
82
+
83
+
Above we are rendering a the Home component for this route. Now we just need to determine what the URL path or route will be to display this component.
84
+
85
+
#### Path
86
+
87
+
The `path` prop will determine what the URL path should be to display the component.
88
+
89
+
```js
90
+
<Route path='/home' component={Home} />
91
+
```
92
+
93
+
Above, we have determined that if the URL ends with '/home' then the Home component will be displayed.
94
+
95
+
#### Exact
96
+
97
+
Another prop that we can add to our Route is `exact`. This prop will tell the route that the URL needs to match up exactly with the path we defined on our Route.
98
+
99
+
```js
100
+
<Route exact path='/home' component={Home} />
101
+
```
102
+
103
+
Above, we have declared the URL needs to end exactly with '/home'. If we have anything following or before the '/home' then the component will not be displayed.
104
+
105
+
This is extremely important to include if we want our base route to be displayed correctly. We can determine what our base route is by creating a route for '/'.
0 commit comments