React Router
React Router is the most popular routing solution in the React ecosystem and has evolved into a full-stack framework. React Router 7 is built on Vite, providing a modern development experience and supporting multiple rendering modes such as server-side rendering and static generation, enabling you to build high-performance full-stack Web applications.
Note:
Currently, Makers supports React Router version 7+ and full-stack deployment.
Core Features
Full-stack framework: Upgraded from a simple routing library to a full-stack framework, supporting integration of front-end and back-end development.
Multiple rendering modes: Supports SSR (server-side rendering), SSG (static generation), SPA (single-page application), and other rendering modes, flexibly adapting to different scenarios.
Nested routes: A powerful nested routing system that supports layout nesting and parallel data loading.
Data loading: Built-in data loading mechanism (loader) and data modification (action) to simplify data access and form processing.
Type-safe routing: Native TypeScript support with full type inference and route type safety.
File-based routing: Supports routing agreement based on file system to simplify routing configuration.
Quick Start
Start deploying your React Router project on EdgeOne Makers:
Import a React Router project from a Git repository.
Select a React Router template from the Makers template library.
Use the @edgeone/react-router framework adapter to deploy a local project.
To understand the deployment performance of React Router on Makers, click the example template below:
Makers Support for React Router
The table below lists the key React Router features currently supported by Makers. The platform will also support more features as soon as possible, but experimental features may not be fully stable yet.
React Router Features | Support Status |
Server-Side Rendering (SSR) | ✓ |
Static Site Generation (SSG) | ✓ |
Single Page Application (SPA) | ✓ |
Route Loaders | ✓ |
Route Actions | ✓ |
Nested Routes | ✓ |
File-based Routing | ✓ |
Streaming | ✓ |
Experimental features | Partially supported |
Deploying a React Router Project on Makers
@edgeone/react-router is a Vite plugin that automatically adapts React Router v7 applications to the Makers platform, and it can work with Makers' scaffolding tools to deploy local React Router.
The project is packaged and deployed to the Makers platform. The main features of @edgeone/react-router are as follows:
Automatic adaptation: Converts React Router v7 applications into a format executable by the Makers platform.
Multi-mode support: Supports SSR, SPA, pre-rendering, and other rendering modes.
Resource optimization: automatic processing and packaging of static resources.
To deploy a React Router project on Makers, refer to the following steps.
1. Installing an Adapter
npm install @edgeone/react-router
2. Configure Vite
In vite.config.ts, introduce and use edgeoneAdapter:
import { reactRouter } from "@react-router/dev/vite";import { defineConfig } from "vite";import { edgeoneAdapter } from "@edgeone/react-router";export default defineConfig({plugins: [reactRouter(),edgeoneAdapter() // add EdgeOne adapter],});
3. Deploying a Project
Git Connection Deployment
After seamless integration with the adapter, you can submit the project to platforms such as GitHub and GitLab, and use our import Git repository.
CLI Deployment
You can also install the Makers scaffolding tool. For detailed installation and usage instructions, see EdgeOne CLI. After configuration, use the `edgeone makers deploy` command to deploy the project. During deployment, the CLI first automatically builds the project, then uploads and publishes the build artifacts.
Note:
EdgeOne CLI version requirement ≥ 1.2.4. Please first check version before deployment to avoid deployment failure.
Server-Side Rendering (SSR)
Server-side rendering allows you to render webpages on servers dynamically. Every time users initiate requests, the server retrieves data and generates HTML in real time, improving SEO and the first-screen loading experience.
In React Router, data can be obtained through the loader function on the server:
// routes/post.tsximport type { Route } from "./+types/post";export async function loader({ params }: Route.LoaderArgs) {const post = await fetchPost(params.id);return { post };}export default function Post({ loaderData }: Route.ComponentProps) {return (<article><h1>{loaderData.post.title}</h1><div>{loaderData.post.content}</div></article>);}
Default build settings are as follows:
Build command:
npm run buildOutput directory:
buildStatic Site Generation (SSG)
React Router supports pre-rendering static pages during build. By configuring the
prerender option, you can generate specified routes as static HTML.Configure in
react-router.config.ts:import type { Config } from "@react-router/dev/config";export default {async prerender() {return ["/","/about","/blog/post-1","/blog/post-2",];},} satisfies Config;
can also dynamically generate pre-rendered routes:
export default {async prerender() {const posts = await fetchAllPosts();return ["/",...posts.map(post => `/blog/${post.slug}`)];},} satisfies Config;
Default build settings are as follows:
Build command:
npm run buildOutput directory:
build/clientSingle-Page Application (SPA) Mode
If server-side functionality is not required, you can configure React Router in pure SPA mode. Set in
react-router.config.ts:import type { Config } from "@react-router/dev/config";export default {ssr: false,} satisfies Config;
Default build settings are as follows:
Build command:
npm run buildOutput directory:
build/clientStreaming Rendering
React Router supports streaming rendering through React 18's Suspense. Page content can be gradually transmitted from the server to the client without waiting for all data to load.
import { Suspense } from "react";import { Await } from "react-router";export async function loader() {// Return a Promise without waitingconst postsPromise = fetchPosts();const weatherPromise = fetchWeather();return {posts: postsPromise,weather: weatherPromise,};}export default function Dashboard({ loaderData }) {return (<div><Suspense fallback={<p>Loading posts...</p>}><Await resolve={loaderData.posts}>{(posts) => <PostList posts={posts} />}</Await></Suspense><Suspense fallback={<p>Loading weather...</p>}><Await resolve={loaderData.weather}>{(weather) => <Weather data={weather} />}</Await></Suspense></div>);}
