| 1 | ---
|
| 2 | title: Installation
|
| 3 | order: 1
|
| 4 | ---
|
| 5 |
|
| 6 | # Installation
|
| 7 |
|
| 8 | [MODES: data]
|
| 9 |
|
| 10 | ## Bootstrap with a Bundler Template
|
| 11 |
|
| 12 | You can start with a React template from Vite and choose "React", otherwise bootstrap your application however you prefer (Parcel, Webpack, etc).
|
| 13 |
|
| 14 | ```shellscript nonumber
|
| 15 | npx create-vite@latest
|
| 16 | ```
|
| 17 |
|
| 18 | ## Install React Router
|
| 19 |
|
| 20 | Next install React Router from npm:
|
| 21 |
|
| 22 | ```shellscript nonumber
|
| 23 | npm i react-router
|
| 24 | ```
|
| 25 |
|
| 26 | ## Create a Router and Render
|
| 27 |
|
| 28 | Create a router and pass it to `RouterProvider`:
|
| 29 |
|
| 30 | ```tsx lines=[3-4,6-11,16]
|
| 31 | import React from "react";
|
| 32 | import ReactDOM from "react-dom/client";
|
| 33 | import { createBrowserRouter } from "react-router";
|
| 34 | import { RouterProvider } from "react-router/dom";
|
| 35 |
|
| 36 | const router = createBrowserRouter([
|
| 37 | {
|
| 38 | path: "/",
|
| 39 | element: <div>Hello World</div>,
|
| 40 | },
|
| 41 | ]);
|
| 42 |
|
| 43 | const root = document.getElementById("root");
|
| 44 |
|
| 45 | ReactDOM.createRoot(root).render(
|
| 46 | <RouterProvider router={router} />,
|
| 47 | );
|
| 48 | ```
|
| 49 |
|
| 50 | ---
|
| 51 |
|
| 52 | Next: [Routing](./routing)
|
| 53 | |
| \ | No newline at end of file |