Skip to content

Commit 0677854

Browse files
committed
added params example
1 parent a171c56 commit 0677854

4 files changed

Lines changed: 16 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,4 @@ const {id} = props.match.params;
196196

197197
or if we console logged `props`, the object would look like the following
198198

199-
![props object](images/props)
199+
![props object](images/props.png)

src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Home from './components/Home';
88
import About from './components/About';
99
import Contact from './components/Contact';
1010
import Navbar from './components/Navbar';
11+
import Profile from './components/Profile';
1112

1213
class App extends Component {
1314
render() {
@@ -18,6 +19,7 @@ class App extends Component {
1819
<Route exact path='/' component={Home} />
1920
<Route path='/about' component={About} />
2021
<Route path='/contact' component={Contact} />
22+
<Route path='/profile/:user_id' component={Profile} />
2123
</Switch>
2224
</div>
2325
)

src/components/Navbar.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const Navbar = () => (
3131
<Link to="/contact" style={linkStyle}>
3232
<span>Contact</span>
3333
</Link>
34+
{/* this will link to the profile for user with id of 1 */}
35+
<Link to="/profile/1" style={linkStyle}>
36+
<span>Profile</span>
37+
</Link>
3438
</nav>
3539
)
3640

src/components/Profile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react'
2+
3+
const Profile = (props) => {
4+
// take the id from props
5+
const {user_id} = props.match.params;
6+
return <h1>This is the user profile for the user with the id of {user_id}</h1>
7+
};
8+
9+
export default Profile;

0 commit comments

Comments
 (0)