Thuta Learning
AdvancedWeb Developmentintermediate

React Router Intro

Relax. We'll talk through this in plain words — no textbook voice.

When a React app needs to switch between views like Home, About, Contact, or Dashboard, you can swap components without a full browser page refresh. This is called client-side routing, and in React it's usually handled with React Router.

jsx
# Install React Router in a Vite React project
npm install react-router-dom

This command adds the `react-router-dom` package to your React app so you can use routing features.

You should see
You can now import and use things like `BrowserRouter`, `Routes`, `Route`, `Link`, and `useParams` in your project.

Info

After installing, you may need to restart the app. Stop the terminal's dev server and run `npm run dev` again.

Easy traps

  • Import it without installing the package first, and you'll get a `Module not found` error.