@remix-run/router
Advanced tools
Comparing version 0.2.0-pre.7 to 0.2.0-pre.8
# @remix-run/router | ||
## 0.2.0-pre.8 | ||
### Patch Changes | ||
- fix: avoid uneccesary re-renders on `defer` resolution (#9155) | ||
- fix: pass `useMatches` objects to `ScrollRestoration` `getKey` (#9157) | ||
- fix: fetcher submission revalidating fetchers using wrong key (#9166) | ||
- fix: use a push navigation on submission errors (#9162) | ||
## 0.2.0-pre.7 | ||
@@ -4,0 +13,0 @@ |
import type { BrowserHistoryOptions, HashHistoryOptions, MemoryHistoryOptions } from "./history"; | ||
import type { Router, RouterInit } from "./router"; | ||
import { convertRoutesToDataRoutes } from "./utils"; | ||
export type { ActionFunction, ActionFunctionArgs, DataRouteMatch, DataRouteObject, TrackedPromise, FormEncType, FormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, RouteMatch, RouteObject, ShouldRevalidateFunction, Submission, } from "./utils"; | ||
export type { ActionFunction, ActionFunctionArgs, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticRouteMatch, AgnosticRouteObject, TrackedPromise, FormEncType, FormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, Submission, } from "./utils"; | ||
export { ErrorResponse, defer, generatePath, getToPathname, invariant, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, resolvePath, resolveTo, stripBasename, warning, } from "./utils"; | ||
@@ -6,0 +6,0 @@ export type { BrowserHistory, HashHistory, History, InitialEntry, Location, MemoryHistory, Path, To, } from "./history"; |
import { History, Location, To } from "./history"; | ||
import { Action as HistoryAction } from "./history"; | ||
import { DataRouteMatch, DataRouteObject, FormEncType, FormMethod, RouteData, RouteObject } from "./utils"; | ||
import { AgnosticDataRouteMatch, AgnosticDataRouteObject, FormEncType, FormMethod, RouteData, AgnosticRouteObject, AgnosticRouteMatch } from "./utils"; | ||
import { DeferredData } from "./utils"; | ||
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
get routes(): DataRouteObject[]; | ||
get routes(): AgnosticDataRouteObject[]; | ||
/** | ||
@@ -109,3 +109,3 @@ * Initialize the router, including adding history listeners and kicking off | ||
*/ | ||
matches: DataRouteMatch[]; | ||
matches: AgnosticDataRouteMatch[]; | ||
/** | ||
@@ -161,3 +161,3 @@ * Tracks whether we've completed our initial data load | ||
basename?: string; | ||
routes: RouteObject[]; | ||
routes: AgnosticRouteObject[]; | ||
history: History; | ||
@@ -184,3 +184,3 @@ hydrationData?: HydrationState; | ||
export interface StaticHandler { | ||
dataRoutes: DataRouteObject[]; | ||
dataRoutes: AgnosticDataRouteObject[]; | ||
query(request: Request): Promise<StaticHandlerContext | Response>; | ||
@@ -195,2 +195,9 @@ queryRoute(request: Request, routeId?: string): Promise<any>; | ||
} | ||
interface UseMatchesMatch { | ||
id: string; | ||
pathname: string; | ||
params: AgnosticRouteMatch["params"]; | ||
data: unknown; | ||
handle: unknown; | ||
} | ||
/** | ||
@@ -201,3 +208,3 @@ * Function signature for determining the key to be used in scroll restoration | ||
export interface GetScrollRestorationKeyFunction { | ||
(location: Location, matches: DataRouteMatch[]): string | null; | ||
(location: Location, matches: UseMatchesMatch[]): string | null; | ||
} | ||
@@ -303,3 +310,3 @@ /** | ||
export declare function createRouter(init: RouterInit): Router; | ||
export declare function unstable_createStaticHandler(routes: RouteObject[]): StaticHandler; | ||
export declare function unstable_createStaticHandler(routes: AgnosticRouteObject[]): StaticHandler; | ||
/** | ||
@@ -309,3 +316,3 @@ * Given an existing StaticHandlerContext and an error thrown at render time, | ||
*/ | ||
export declare function getStaticContextFromError(routes: DataRouteObject[], context: StaticHandlerContext, error: any): StaticHandlerContext; | ||
export declare function getStaticContextFromError(routes: AgnosticDataRouteObject[], context: StaticHandlerContext, error: any): StaticHandlerContext; | ||
export {}; |
@@ -1,2 +0,1 @@ | ||
/// <reference types="react" /> | ||
import type { Location, Path, To } from "./history"; | ||
@@ -9,4 +8,2 @@ /** | ||
} | ||
export interface DataRouteMatch extends RouteMatch<string, DataRouteObject> { | ||
} | ||
export declare enum ResultType { | ||
@@ -108,5 +105,5 @@ data = "data", | ||
currentUrl: URL; | ||
currentParams: DataRouteMatch["params"]; | ||
currentParams: AgnosticDataRouteMatch["params"]; | ||
nextUrl: URL; | ||
nextParams: DataRouteMatch["params"]; | ||
nextParams: AgnosticDataRouteMatch["params"]; | ||
formMethod?: Submission["formMethod"]; | ||
@@ -124,6 +121,5 @@ formAction?: Submission["formAction"]; | ||
*/ | ||
export interface RouteObject { | ||
export interface AgnosticRouteObject { | ||
caseSensitive?: boolean; | ||
children?: RouteObject[]; | ||
element?: React.ReactNode; | ||
children?: AgnosticRouteObject[]; | ||
index?: boolean; | ||
@@ -134,3 +130,3 @@ path?: string; | ||
action?: ActionFunction; | ||
errorElement?: React.ReactNode; | ||
hasErrorBoundary?: boolean; | ||
shouldRevalidate?: ShouldRevalidateFunction; | ||
@@ -142,4 +138,4 @@ handle?: any; | ||
*/ | ||
export interface DataRouteObject extends RouteObject { | ||
children?: DataRouteObject[]; | ||
export interface AgnosticDataRouteObject extends AgnosticRouteObject { | ||
children?: AgnosticDataRouteObject[]; | ||
id: string; | ||
@@ -170,3 +166,3 @@ } | ||
*/ | ||
export interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> { | ||
export interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> { | ||
/** | ||
@@ -189,3 +185,5 @@ * The names and values of dynamic parameters in the URL. | ||
} | ||
export declare function convertRoutesToDataRoutes(routes: RouteObject[], parentPath?: number[], allIds?: Set<string>): DataRouteObject[]; | ||
export interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> { | ||
} | ||
export declare function convertRoutesToDataRoutes(routes: AgnosticRouteObject[], parentPath?: number[], allIds?: Set<string>): AgnosticDataRouteObject[]; | ||
/** | ||
@@ -196,3 +194,3 @@ * Matches the given routes to a location and returns the match data. | ||
*/ | ||
export declare function matchRoutes<RouteObjectType extends RouteObject = RouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): RouteMatch<string, RouteObjectType>[] | null; | ||
export declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null; | ||
/** | ||
@@ -276,3 +274,3 @@ * Returns a path with params interpolated. | ||
*/ | ||
export declare function resolveTo(toArg: To, routePathnames: string[], locationPathname: string): Path; | ||
export declare function resolveTo(toArg: To, routePathnames: string[], locationPathname: string, isPathRelative?: boolean): Path; | ||
/** | ||
@@ -279,0 +277,0 @@ * @private |
@@ -18,4 +18,6 @@ import type { | ||
ActionFunctionArgs, | ||
DataRouteMatch, | ||
DataRouteObject, | ||
AgnosticDataRouteMatch, | ||
AgnosticDataRouteObject, | ||
AgnosticRouteMatch, | ||
AgnosticRouteObject, | ||
TrackedPromise, | ||
@@ -32,4 +34,2 @@ FormEncType, | ||
RedirectFunction, | ||
RouteMatch, | ||
RouteObject, | ||
ShouldRevalidateFunction, | ||
@@ -36,0 +36,0 @@ Submission, |
{ | ||
"name": "@remix-run/router", | ||
"version": "0.2.0-pre.7", | ||
"version": "0.2.0-pre.8", | ||
"description": "Nested/Data-driven/Framework-agnostic Routing", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
64
utils.ts
@@ -11,4 +11,2 @@ import type { Location, Path, To } from "./history"; | ||
export interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {} | ||
export enum ResultType { | ||
@@ -127,5 +125,5 @@ data = "data", | ||
currentUrl: URL; | ||
currentParams: DataRouteMatch["params"]; | ||
currentParams: AgnosticDataRouteMatch["params"]; | ||
nextUrl: URL; | ||
nextParams: DataRouteMatch["params"]; | ||
nextParams: AgnosticDataRouteMatch["params"]; | ||
formMethod?: Submission["formMethod"]; | ||
@@ -144,6 +142,5 @@ formAction?: Submission["formAction"]; | ||
*/ | ||
export interface RouteObject { | ||
export interface AgnosticRouteObject { | ||
caseSensitive?: boolean; | ||
children?: RouteObject[]; | ||
element?: React.ReactNode; | ||
children?: AgnosticRouteObject[]; | ||
index?: boolean; | ||
@@ -154,3 +151,3 @@ path?: string; | ||
action?: ActionFunction; | ||
errorElement?: React.ReactNode; | ||
hasErrorBoundary?: boolean; | ||
shouldRevalidate?: ShouldRevalidateFunction; | ||
@@ -163,4 +160,4 @@ handle?: any; | ||
*/ | ||
export interface DataRouteObject extends RouteObject { | ||
children?: DataRouteObject[]; | ||
export interface AgnosticDataRouteObject extends AgnosticRouteObject { | ||
children?: AgnosticDataRouteObject[]; | ||
id: string; | ||
@@ -216,5 +213,5 @@ } | ||
*/ | ||
export interface RouteMatch< | ||
export interface AgnosticRouteMatch< | ||
ParamKey extends string = string, | ||
RouteObjectType extends RouteObject = RouteObject | ||
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject | ||
> { | ||
@@ -239,9 +236,12 @@ /** | ||
export interface AgnosticDataRouteMatch | ||
extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {} | ||
// Walk the route tree generating unique IDs where necessary so we are working | ||
// solely with DataRouteObject's within the Router | ||
export function convertRoutesToDataRoutes( | ||
routes: RouteObject[], | ||
routes: AgnosticRouteObject[], | ||
parentPath: number[] = [], | ||
allIds: Set<string> = new Set<string>() | ||
): DataRouteObject[] { | ||
): AgnosticDataRouteObject[] { | ||
return routes.map((route, index) => { | ||
@@ -256,3 +256,3 @@ let treePath = [...parentPath, index]; | ||
allIds.add(id); | ||
let dataRoute: DataRouteObject = { | ||
let dataRoute: AgnosticDataRouteObject = { | ||
...route, | ||
@@ -273,7 +273,9 @@ id, | ||
*/ | ||
export function matchRoutes<RouteObjectType extends RouteObject = RouteObject>( | ||
export function matchRoutes< | ||
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject | ||
>( | ||
routes: RouteObjectType[], | ||
locationArg: Partial<Location> | string, | ||
basename = "/" | ||
): RouteMatch<string, RouteObjectType>[] | null { | ||
): AgnosticRouteMatch<string, RouteObjectType>[] | null { | ||
let location = | ||
@@ -299,3 +301,5 @@ typeof locationArg === "string" ? parsePath(locationArg) : locationArg; | ||
interface RouteMeta<RouteObjectType extends RouteObject = RouteObject> { | ||
interface RouteMeta< | ||
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject | ||
> { | ||
relativePath: string; | ||
@@ -307,3 +311,5 @@ caseSensitive: boolean; | ||
interface RouteBranch<RouteObjectType extends RouteObject = RouteObject> { | ||
interface RouteBranch< | ||
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject | ||
> { | ||
path: string; | ||
@@ -314,3 +320,5 @@ score: number; | ||
function flattenRoutes<RouteObjectType extends RouteObject = RouteObject>( | ||
function flattenRoutes< | ||
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject | ||
>( | ||
routes: RouteObjectType[], | ||
@@ -429,7 +437,7 @@ branches: RouteBranch<RouteObjectType>[] = [], | ||
ParamKey extends string = string, | ||
RouteObjectType extends RouteObject = RouteObject | ||
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject | ||
>( | ||
branch: RouteBranch<RouteObjectType>, | ||
pathname: string | ||
): RouteMatch<ParamKey, RouteObjectType>[] | null { | ||
): AgnosticRouteMatch<ParamKey, RouteObjectType>[] | null { | ||
let { routesMeta } = branch; | ||
@@ -439,3 +447,3 @@ | ||
let matchedPathname = "/"; | ||
let matches: RouteMatch<ParamKey, RouteObjectType>[] = []; | ||
let matches: AgnosticRouteMatch<ParamKey, RouteObjectType>[] = []; | ||
for (let i = 0; i < routesMeta.length; ++i) { | ||
@@ -775,3 +783,4 @@ let meta = routesMeta[i]; | ||
routePathnames: string[], | ||
locationPathname: string | ||
locationPathname: string, | ||
isPathRelative = false | ||
): Path { | ||
@@ -782,2 +791,6 @@ let to = typeof toArg === "string" ? parsePath(toArg) : { ...toArg }; | ||
let from: string; | ||
// Routing is relative to the current pathname if explicitly requested. | ||
// | ||
// If a pathname is explicitly provided in `to`, it should be relative to the | ||
@@ -790,4 +803,3 @@ // route context. This is explained in `Note on `<Link to>` values` in our | ||
// to the current location's pathname and *not* the route pathname. | ||
let from: string; | ||
if (toPathname == null) { | ||
if (isPathRelative || toPathname == null) { | ||
from = locationPathname; | ||
@@ -794,0 +806,0 @@ } else { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
846986
10217