← All articles
React Route v6.8.0 Setup featured image

React Route v6.8.0 Setup

A quick reference for setting up React Router v6.8.0 with basic routing patterns.

January 30, 2023·Jacky FAN·1 min read

Every several months when I want to set up React Route in my React project, the setup process is always different from the previous one. Therefore, I am writing a quick memo to note the setup of React Route and its basic usage.

Setup React Route

bash
 cd myReactProjectyarn add react-router-dom@6 # currently v6.8.0nvim src/App.tsx    # or any file you want to put it in 

App.tsx

jsx
 import "./App.css"; // 1. Insert this importimport {  createBrowserRouter,  RouterProvider,} from "react-router-dom"; import { HomePage, NewPage } from "./pages"; // 2. Create new Routesconst router = createBrowserRouter([  {    path: "/",    element: <HomePage />,  },  {    path: "/newPage",    element: <NewPage />,  },]); function App() {    // 3. Insert Router Provider    return <RouterProvider router={router} />;} export default App;   

Basic Usage

jsx
 import { Link, useNavigate } from "react-router-dom"; // Example of a link in React Routerconst ExampleLink = () => {  return <Link to="/newPage">Click Me</Link>} // Example of a navigate button in React Routerconst ExampleButton = () => {  const navigate = useNavigate();   return <button onClick={()=>{navigate("/newPage")}}>Click me</button>} 

Reference: Tutorial - React Route

Continue ReadingView all articles →
How to apply Google's font with NuxtJS and Tailwind featured image
FrontendAugust 13, 2023

How to apply Google's font with NuxtJS and Tailwind

How To Setup Code Highlighting In Nuxt Content featured image
FrontendJune 26, 2023

How To Setup Code Highlighting In Nuxt Content

How Hermes Agent Redesigned Both My Websites featured image
Hermes AgentJuly 6, 2026

How Hermes Agent Redesigned Both My Websites

Next ArticleHow To Setup Code Highlighting In Nuxt Content