File tree Expand file tree Collapse file tree 4 files changed +23
-20
lines changed Expand file tree Collapse file tree 4 files changed +23
-20
lines changed Original file line number Diff line number Diff line change @@ -447,6 +447,20 @@ export function createHashHistory(
447447//#region UTILS
448448////////////////////////////////////////////////////////////////////////////////
449449
450+ /**
451+ * @private
452+ */
453+ export function invariant ( value : boolean , message ?: string ) : asserts value ;
454+ export function invariant < T > (
455+ value : T | null | undefined ,
456+ message ?: string
457+ ) : asserts value is T ;
458+ export function invariant ( value : any , message ?: string ) {
459+ if ( value === false || value === null || typeof value === "undefined" ) {
460+ throw new Error ( message ) ;
461+ }
462+ }
463+
450464function warning ( cond : any , message : string ) {
451465 if ( ! cond ) {
452466 // eslint-disable-next-line no-console
@@ -553,9 +567,13 @@ export function createClientSideURL(location: Location | string): URL {
553567 typeof window . location !== "undefined" &&
554568 window . location . origin !== "null"
555569 ? window . location . origin
556- : "unknown://unknown" ;
570+ : null ;
557571 let href = typeof location === "string" ? location : createPath ( location ) ;
558- return new URL ( href , base ) ;
572+ invariant (
573+ base ,
574+ `No window.location.origin available to create URL for href: ${ href } `
575+ ) ;
576+ return new URL ( href , window . location . origin ) ;
559577}
560578
561579export interface UrlHistory extends History { }
Original file line number Diff line number Diff line change @@ -32,7 +32,6 @@ export {
3232 defer ,
3333 generatePath ,
3434 getToPathname ,
35- invariant ,
3635 isRouteErrorResponse ,
3736 joinPaths ,
3837 json ,
@@ -59,13 +58,13 @@ export type {
5958 Path ,
6059 To ,
6160} from "./history" ;
62-
6361export {
6462 Action ,
6563 createBrowserHistory ,
6664 createPath ,
6765 createHashHistory ,
6866 createMemoryHistory ,
67+ invariant ,
6968 parsePath ,
7069} from "./history" ;
7170
Original file line number Diff line number Diff line change 44 createLocation ,
55 createPath ,
66 createClientSideURL ,
7+ invariant ,
78 parsePath ,
89} from "./history" ;
910import type {
@@ -28,7 +29,6 @@ import {
2829 ResultType ,
2930 convertRoutesToDataRoutes ,
3031 getPathContributingMatches ,
31- invariant ,
3232 isRouteErrorResponse ,
3333 joinPaths ,
3434 matchRoutes ,
Original file line number Diff line number Diff line change 11import type { Location , Path , To } from "./history" ;
2- import { parsePath } from "./history" ;
2+ import { invariant , parsePath } from "./history" ;
33
44/**
55 * Map of routeId -> data returned from a loader/action/error
@@ -771,20 +771,6 @@ export function stripBasename(
771771 return pathname . slice ( startIndex ) || "/" ;
772772}
773773
774- /**
775- * @private
776- */
777- export function invariant ( value : boolean , message ?: string ) : asserts value ;
778- export function invariant < T > (
779- value : T | null | undefined ,
780- message ?: string
781- ) : asserts value is T ;
782- export function invariant ( value : any , message ?: string ) {
783- if ( value === false || value === null || typeof value === "undefined" ) {
784- throw new Error ( message ) ;
785- }
786- }
787-
788774/**
789775 * @private
790776 */
You can’t perform that action at this time.
0 commit comments