Skip to content

Commit

Permalink
Rename RoutesConfig to RouteConfig (#11919)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Aug 22, 2024
1 parent 9bf91e4 commit c34cbeb
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 108 deletions.
4 changes: 2 additions & 2 deletions docs/start/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ export default function Home() {

```ts filename=app/routes.ts
import {
type RoutesConfig,
type RouteConfig,
index,
} from "@react-router/dev/routes";

export const routes: RoutesConfig = [index("./home.tsx")];
export const routes: RouteConfig = [index("./home.tsx")];
```

```tsx filename=vite.config.ts
Expand Down
24 changes: 12 additions & 12 deletions docs/start/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Routes are configured in `app/routes.ts`. The Vite plugin uses this file to crea

```ts filename=app/routes.ts
import {
type RoutesConfig,
type RouteConfig,
route,
index,
layout,
} from "@react-router/dev/routes";

export const routes: RoutesConfig = [
export const routes: RouteConfig = [
index("./home.tsx"),
route("about", "./about.tsx"),

Expand All @@ -39,22 +39,22 @@ export const routes: RoutesConfig = [
If you prefer a file system routing convention, you can use the convention provided with Remix v2, but you can also make your own.

```tsx filename=app/routes.ts
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
import { remixRoutes } from "@react-router/remix-v2-routes";

export const routes: RoutesConfig = remixRoutes();
export const routes: RouteConfig = remixRoutes();
```

You can also mix routing conventions into a single array of routes.

```tsx filename=app/routes.ts
import {
type RoutesConfig,
type RouteConfig,
route,
} from "@react-router/dev/routes";
import { remixRoutes } from "@react-router/remix-v2-routes";

export const routes: RoutesConfig = [
export const routes: RouteConfig = [
// Provide Remix v2 file system routes
...(await remixRoutes()),

Expand Down Expand Up @@ -92,12 +92,12 @@ Routes can be nested inside parent routes. Nested routes are rendered into their

```ts filename=app/routes.ts
import {
type RoutesConfig,
type RouteConfig,
route,
index,
} from "@react-router/dev/routes";

export const routes: RoutesConfig = [
export const routes: RouteConfig = [
route("dashboard", "./dashboard.tsx", [
index("./home.tsx"),
route("settings", "./settings.tsx"),
Expand Down Expand Up @@ -127,13 +127,13 @@ Using `layout`, layout routes create new nesting for their children, but they do

```tsx filename=app/routes.ts lines=[9,15]
import {
type RoutesConfig,
type RouteConfig,
route,
layout,
index,
} from "@react-router/dev/routes";

export const routes: RoutesConfig = [
export const routes: RouteConfig = [
layout("./marketing/layout.tsx", [
index("./marketing/home.tsx"),
route("contact", "./marketing/contact.tsx"),
Expand All @@ -158,12 +158,12 @@ Index routes render into their parent's [Outlet][outlet] at their parent's URL (

```ts filename=app/routes.ts
import {
type RoutesConfig,
type RouteConfig,
route,
index,
} from "@react-router/dev/routes";

export const routes: RoutesConfig = [
export const routes: RouteConfig = [
// renders into the root.tsx Outlet at /
index("./home.tsx"),
route("dashboard", "./dashboard.tsx", [
Expand Down
8 changes: 4 additions & 4 deletions docs/upgrading/vite-component-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ To get back to rendering your app, we'll configure a "catchall" route that match
Create a file at `src/routes.ts` and add this:

```ts filename=src/routes.ts
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";

export const routes: RoutesConfig = [
export const routes: RouteConfig = [
{
path: "*",
file: "src/catchall.tsx",
Expand Down Expand Up @@ -221,9 +221,9 @@ export default function App() {
You can move the definition to a `routes.ts` file:

```tsx filename=src/routes.ts
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";

export const routes: RoutesConfig = [
export const routes: RouteConfig = [
{
path: "/pages/:id",
file: "./containers/page.tsx",
Expand Down
4 changes: 2 additions & 2 deletions docs/upgrading/vite-router-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ ReactDOM.hydrateRoot(
You can move the definition to a `routes.ts` file:

```tsx filename=src/routes.ts
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";

export const routes: RoutesConfig = [
export const routes: RouteConfig = [
{
path: "/pages/:id",
file: "./containers/page.tsx",
Expand Down
4 changes: 2 additions & 2 deletions integration/helpers/node-template/app/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
import { remixRoutes } from "@react-router/remix-v2-routes";

export const routes: RoutesConfig = remixRoutes();
export const routes: RouteConfig = remixRoutes();
4 changes: 2 additions & 2 deletions integration/helpers/vite-cloudflare-template/app/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
import { remixRoutes } from "@react-router/remix-v2-routes";

export const routes: RoutesConfig = remixRoutes();
export const routes: RouteConfig = remixRoutes();
4 changes: 2 additions & 2 deletions integration/helpers/vite-template/app/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
import { remixRoutes } from "@react-router/remix-v2-routes";

export const routes: RoutesConfig = remixRoutes();
export const routes: RouteConfig = remixRoutes();
4 changes: 2 additions & 2 deletions integration/remix-v2-routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ test.describe("remix v2 routes", () => {
});
`,
"app/routes.ts": js`
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
import { remixRoutes } from "@react-router/remix-v2-routes";
export const routes: RoutesConfig = remixRoutes({
export const routes: RouteConfig = remixRoutes({
ignoredRouteFiles: ["**/ignored-route.*"],
routes: async (defineRoutes) => {
// Ensure async routes work
Expand Down
12 changes: 6 additions & 6 deletions integration/routes-config-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ test.describe("routes config", () => {
let files: Files = async ({ port }) => ({
"vite.config.js": await viteConfig.basic({ port }),
"app/routes.ts": js`
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
export const routes: RoutesConfig = [
export const routes: RouteConfig = [
{
file: "test-route-1.tsx",
index: true,
Expand Down Expand Up @@ -114,9 +114,9 @@ test.describe("routes config", () => {
export { routes } from "./actual-routes";
`,
"app/actual-routes.ts": js`
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
export const routes: RoutesConfig = [
export const routes: RouteConfig = [
{
file: "test-route-1.tsx",
index: true,
Expand Down Expand Up @@ -166,9 +166,9 @@ test.describe("routes config", () => {
let files: Files = async ({ port }) => ({
"vite.config.js": await viteConfig.basic({ port }),
"app/routes.ts": js`
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
export const routes: RoutesConfig = [
export const routes: RouteConfig = [
{
file: "test-route-1.tsx",
index: true,
Expand Down
8 changes: 4 additions & 4 deletions integration/vite-spa-mode-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,10 @@ test.describe("SPA Mode", () => {
});
`,
"src/routes.ts": js`
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
import { remixRoutes } from "@react-router/remix-v2-routes";
export const routes: RoutesConfig = remixRoutes();
export const routes: RouteConfig = remixRoutes();
`,
"src/root.tsx": js`
import {
Expand Down Expand Up @@ -592,10 +592,10 @@ test.describe("SPA Mode", () => {
});
`,
"src/routes.ts": js`
import { type RoutesConfig } from "@react-router/dev/routes";
import { type RouteConfig } from "@react-router/dev/routes";
import { remixRoutes } from "@react-router/remix-v2-routes";
export const routes: RoutesConfig = remixRoutes();
export const routes: RouteConfig = remixRoutes();
`,
"src/root.tsx": js`
import {
Expand Down
52 changes: 26 additions & 26 deletions packages/react-router-dev/config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export interface RouteManifest {
[routeId: string]: RouteManifestEntry;
}

export type RoutesConfig = RoutesConfigEntry[] | Promise<RoutesConfigEntry[]>;
export type RouteConfig = RouteConfigEntry[] | Promise<RouteConfigEntry[]>;

/**
* A route exported from the routes config file
*/
export interface RoutesConfigEntry {
export interface RouteConfigEntry {
/**
* The unique id for this route.
*/
Expand Down Expand Up @@ -87,7 +87,7 @@ export interface RoutesConfigEntry {
/**
* The child routes.
*/
children?: RoutesConfigEntry[];
children?: RouteConfigEntry[];
}

type CreateRoutePath = string | null | undefined;
Expand All @@ -101,28 +101,28 @@ const createConfigRouteOptionKeys = [
"id",
"index",
"caseSensitive",
] as const satisfies Array<keyof RoutesConfigEntry>;
] as const satisfies Array<keyof RouteConfigEntry>;
type CreateRouteOptions = Pick<
RoutesConfigEntry,
RouteConfigEntry,
(typeof createConfigRouteOptionKeys)[number]
>;
function createRoute(
path: CreateRoutePath,
file: string,
children?: RoutesConfigEntry[]
): RoutesConfigEntry;
children?: RouteConfigEntry[]
): RouteConfigEntry;
function createRoute(
path: CreateRoutePath,
file: string,
options: RequireAtLeastOne<CreateRouteOptions>,
children?: RoutesConfigEntry[]
): RoutesConfigEntry;
children?: RouteConfigEntry[]
): RouteConfigEntry;
function createRoute(
path: CreateRoutePath,
file: string,
optionsOrChildren: CreateRouteOptions | RoutesConfigEntry[] | undefined,
children?: RoutesConfigEntry[]
): RoutesConfigEntry {
optionsOrChildren: CreateRouteOptions | RouteConfigEntry[] | undefined,
children?: RouteConfigEntry[]
): RouteConfigEntry {
let options: CreateRouteOptions = {};

if (Array.isArray(optionsOrChildren) || !optionsOrChildren) {
Expand All @@ -140,16 +140,16 @@ function createRoute(
}

const createIndexOptionKeys = ["id"] as const satisfies Array<
keyof RoutesConfigEntry
keyof RouteConfigEntry
>;
type CreateIndexOptions = Pick<
RoutesConfigEntry,
RouteConfigEntry,
(typeof createIndexOptionKeys)[number]
>;
function createIndex(
file: string,
options?: RequireAtLeastOne<CreateIndexOptions>
): RoutesConfigEntry {
): RouteConfigEntry {
return {
file,
index: true,
Expand All @@ -158,26 +158,26 @@ function createIndex(
}

const createLayoutOptionKeys = ["id"] as const satisfies Array<
keyof RoutesConfigEntry
keyof RouteConfigEntry
>;
type CreateLayoutOptions = Pick<
RoutesConfigEntry,
RouteConfigEntry,
(typeof createLayoutOptionKeys)[number]
>;
function createLayout(
file: string,
children?: RoutesConfigEntry[]
): RoutesConfigEntry;
children?: RouteConfigEntry[]
): RouteConfigEntry;
function createLayout(
file: string,
options: RequireAtLeastOne<CreateLayoutOptions>,
children?: RoutesConfigEntry[]
): RoutesConfigEntry;
children?: RouteConfigEntry[]
): RouteConfigEntry;
function createLayout(
file: string,
optionsOrChildren: CreateLayoutOptions | RoutesConfigEntry[] | undefined,
children?: RoutesConfigEntry[]
): RoutesConfigEntry {
optionsOrChildren: CreateLayoutOptions | RouteConfigEntry[] | undefined,
children?: RouteConfigEntry[]
): RouteConfigEntry {
let options: CreateLayoutOptions = {};

if (Array.isArray(optionsOrChildren) || !optionsOrChildren) {
Expand All @@ -198,12 +198,12 @@ export const index = createIndex;
export const layout = createLayout;

export function configRoutesToRouteManifest(
routes: RoutesConfigEntry[],
routes: RouteConfigEntry[],
rootId = "root"
): RouteManifest {
let routeManifest: RouteManifest = {};

function walk(route: RoutesConfigEntry, parentId: string) {
function walk(route: RouteConfigEntry, parentId: string) {
let id = route.id || createRouteId(route.file);
let manifestItem: RouteManifestEntry = {
id,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dev/routes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type { RoutesConfig, RoutesConfigEntry } from "./config/routes";
export type { RouteConfig, RouteConfigEntry } from "./config/routes";

export { route, index, layout, getAppDirectory } from "./config/routes";
Loading

0 comments on commit c34cbeb

Please sign in to comment.