Top Related Projects
Declarative routing for React
🥢 A minimalist-friendly ~2.1KB routing for React and Preact
🧭 Declarative, asynchronous routing for React.
🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering.
Quick Overview
React Router Tutorial is an official educational repository by the React Router team, designed to teach developers how to use React Router effectively in their React applications. It provides step-by-step lessons and examples to help users understand routing concepts and implementation in React.
Pros
- Comprehensive and well-structured learning path
- Official resource, ensuring accuracy and best practices
- Includes practical examples and exercises
- Regularly updated to reflect the latest React Router version
Cons
- May not cover advanced use cases or edge scenarios
- Focused solely on React Router, not covering other routing solutions
- Some users might prefer video tutorials over text-based lessons
- Requires basic React knowledge, which might be challenging for complete beginners
Code Examples
- Basic route setup:
import { BrowserRouter, Routes, Route } from "react-router-dom";
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="about" element={<About />} />
<Route path="contact" element={<Contact />} />
</Routes>
</BrowserRouter>
);
}
- Using route parameters:
import { useParams } from "react-router-dom";
function UserProfile() {
let { userId } = useParams();
return <div>User Profile for ID: {userId}</div>;
}
// In your route configuration:
<Route path="users/:userId" element={<UserProfile />} />
- Programmatic navigation:
import { useNavigate } from "react-router-dom";
function NavigationExample() {
let navigate = useNavigate();
function handleClick() {
navigate("/dashboard");
}
return (
<button onClick={handleClick}>Go to Dashboard</button>
);
}
Getting Started
To get started with the React Router Tutorial:
-
Clone the repository:
git clone https://github.com/reactjs/react-router-tutorial.git
-
Navigate to the project directory:
cd react-router-tutorial
-
Install dependencies:
npm install
-
Start the development server:
npm start
-
Open your browser and navigate to
http://localhost:3000
to begin the tutorial.
Follow the lessons in order, starting from the basics and progressing through more advanced concepts. Each lesson includes explanations, code examples, and exercises to reinforce your learning.
Competitor Comparisons
Declarative routing for React
Pros of React Router
- More comprehensive and feature-rich, offering advanced routing capabilities
- Actively maintained with regular updates and improvements
- Extensive documentation and community support
Cons of React Router
- Steeper learning curve for beginners
- Potentially more complex setup for simple applications
- Larger bundle size due to additional features
Code Comparison
React Router Tutorial:
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
<Router>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
</Router>
React Router:
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
const router = createBrowserRouter([
{ path: "/", element: <Home /> },
{ path: "/about", element: <About /> },
]);
<RouterProvider router={router} />
The React Router Tutorial repository provides a simpler, more straightforward approach to routing, making it ideal for beginners or small projects. However, it may lack some of the advanced features and flexibility offered by the full React Router library.
React Router, on the other hand, offers a more powerful and flexible routing solution, with features like nested routes, route parameters, and programmatic navigation. It's better suited for larger, more complex applications but may be overkill for simple projects.
Pros of Reach Router
- Simpler API with less boilerplate code
- Built-in accessibility features
- Better support for nested routing
Cons of Reach Router
- Less widely adopted compared to React Router
- Fewer advanced features for complex routing scenarios
- Limited documentation and community resources
Code Comparison
React Router Tutorial:
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
<Router>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
</Router>
Reach Router:
import { Router, Link } from '@reach/router';
<Router>
<Home path="/" />
<About path="about" />
</Router>
The code comparison shows that Reach Router has a more concise syntax for defining routes. It doesn't require the exact
prop for the home route and uses a simpler path
prop instead of a separate Route
component.
Reach Router also provides better accessibility out of the box, with focus management and live region announcements. However, React Router Tutorial (part of the React Router ecosystem) has more extensive documentation, a larger community, and more advanced features for complex routing scenarios.
Both libraries serve the purpose of handling routing in React applications, but Reach Router aims for simplicity and accessibility, while React Router offers more flexibility and advanced features.
🥢 A minimalist-friendly ~2.1KB routing for React and Preact
Pros of wouter
- Lightweight and minimalistic, with a smaller bundle size
- Simple API that's easy to learn and use
- No external dependencies, reducing potential conflicts
Cons of wouter
- Less feature-rich compared to React Router
- Smaller community and ecosystem
- May lack advanced routing capabilities for complex applications
Code Comparison
React Router Tutorial:
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
function App() {
return (
<Router>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
</Router>
);
}
wouter:
import { Router, Route, Link } from "wouter";
function App() {
return (
<>
<Route path="/" component={Home} />
<Route path="/about" component={About} />
</>
);
}
The code comparison shows that wouter has a simpler syntax and doesn't require wrapping the entire app in a Router component. React Router Tutorial offers more explicit routing control with the exact
prop and the BrowserRouter
component.
Both libraries provide similar basic routing functionality, but React Router Tutorial offers more advanced features and configuration options out of the box, while wouter focuses on simplicity and minimal overhead.
🧭 Declarative, asynchronous routing for React.
Pros of Navi
- Built-in code splitting and asynchronous data loading
- Simpler API with less boilerplate code
- Better TypeScript support and type inference
Cons of Navi
- Smaller community and ecosystem compared to React Router
- Less documentation and learning resources available
- May require more setup for complex routing scenarios
Code Comparison
React Router Tutorial:
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
function App() {
return (
<Router>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
</Router>
);
}
Navi:
import { Router, Route, View } from 'react-navi';
const routes = mount({
'/': route({ view: <Home /> }),
'/about': route({ view: <About /> }),
});
function App() {
return <Router routes={routes}><View /></Router>;
}
Both libraries provide routing solutions for React applications, but Navi offers a more modern approach with built-in features like code splitting and async data loading. React Router Tutorial, being part of the React Router ecosystem, has a larger community and more extensive documentation. Navi's API is generally simpler and requires less boilerplate, while React Router Tutorial may be more familiar to developers who have worked with React Router before. The choice between the two depends on project requirements and developer preferences.
🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering.
Pros of TanStack Router
- Type-safe routing with automatic type inference
- Built-in data fetching and caching capabilities
- Framework-agnostic, can be used with React, Vue, or vanilla JavaScript
Cons of TanStack Router
- Steeper learning curve due to its more complex API
- Less community support and resources compared to React Router
- May be overkill for simple routing needs
Code Comparison
React Router Tutorial:
import { BrowserRouter, Route, Link } from "react-router-dom";
function App() {
return (
<BrowserRouter>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</BrowserRouter>
);
}
TanStack Router:
import { Router, Route, RootRoute } from "@tanstack/react-router";
const rootRoute = new RootRoute();
const indexRoute = new Route({
getParentRoute: () => rootRoute,
path: "/",
component: Home,
});
const aboutRoute = new Route({
getParentRoute: () => rootRoute,
path: "/about",
component: About,
});
const routeTree = rootRoute.addChildren([indexRoute, aboutRoute]);
const router = new Router({ routeTree });
The React Router Tutorial provides a simpler, more declarative approach to routing, while TanStack Router offers more advanced features and type safety at the cost of increased complexity.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
React Router Tutorial
Quick lessons for getting up-to-speed with React Router.
See Lesson 1 - Setting Up to get started.
Each lesson is a fully runnable app with all code from the previous lesson, so you can cd lessons/<lesson-folder>
, npm install,
and then run the appropriate NPM scripts for each lesson from within the lesson folder.
Missing stuff that will come eventually, hopefully ... maybe.
- an app that isn't completely pointless
- egghead.io videos
- code splitting
- location state
- data integration
Top Related Projects
Declarative routing for React
🥢 A minimalist-friendly ~2.1KB routing for React and Preact
🧭 Declarative, asynchronous routing for React.
🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot