boring-router-react
Advanced tools
Comparing version 0.3.8 to 0.3.9
import { AbstractHistory, HistorySnapshot } from 'boring-router'; | ||
export declare type BrowserHistoryNavigateAwayHandler = (href: string) => void; | ||
declare type BrowserHistorySnapshot<TData> = HistorySnapshot<number, TData>; | ||
@@ -35,3 +36,3 @@ export interface BrowserHistoryOptions { | ||
restore(snapshot: BrowserHistorySnapshot<TData>): Promise<void>; | ||
navigate(href: string): Promise<void>; | ||
navigate(href: string, navigateAwayHandler?: BrowserHistoryNavigateAwayHandler): Promise<void>; | ||
private onPopState; | ||
@@ -38,0 +39,0 @@ private stepRestoration; |
@@ -8,2 +8,5 @@ "use strict"; | ||
const debug = debug_1.default('boring-router:react:browser-history'); | ||
const NAVIGATE_AWAY_HANDLER_DEFAULT = href => { | ||
location.href = href; | ||
}; | ||
class BrowserHistory extends boring_router_1.AbstractHistory { | ||
@@ -143,6 +146,17 @@ constructor({ prefix = '', hash = false } = {}) { | ||
} | ||
async navigate(href) { | ||
async navigate(href, navigateAwayHandler = NAVIGATE_AWAY_HANDLER_DEFAULT) { | ||
let originalHRef = href; | ||
let groups = /^([\w\d]+:)?\/\/([^/?]+)(.*)/.exec(href); | ||
if (groups) { | ||
let [, protocol, host, rest] = groups; | ||
if ((protocol && protocol !== location.protocol) || | ||
host !== location.host) { | ||
navigateAwayHandler(originalHRef); | ||
return; | ||
} | ||
href = rest.startsWith('/') ? rest : `/${rest}`; | ||
} | ||
let prefix = this.prefix; | ||
if (/^[\w\d]+:\/\//.test(href) || !href.startsWith(prefix)) { | ||
location.href = href; | ||
if (!href.startsWith(prefix)) { | ||
navigateAwayHandler(originalHRef); | ||
return; | ||
@@ -149,0 +163,0 @@ } |
{ | ||
"name": "boring-router-react", | ||
"version": "0.3.8", | ||
"version": "0.3.9", | ||
"description": "A type-safe MobX router with parallel routing support.", | ||
@@ -36,3 +36,3 @@ "repository": { | ||
}, | ||
"gitHead": "baf47b709c4dd6d9b33c618560e0a7e3b16340ad" | ||
"gitHead": "0cfb15ee48417a6b56cc9bd97fc311a6e2e6f454" | ||
} |
@@ -12,2 +12,8 @@ import { | ||
export type BrowserHistoryNavigateAwayHandler = (href: string) => void; | ||
const NAVIGATE_AWAY_HANDLER_DEFAULT: BrowserHistoryNavigateAwayHandler = href => { | ||
location.href = href; | ||
}; | ||
type BrowserHistoryEntry<TData> = HistoryEntry<number, TData>; | ||
@@ -194,7 +200,28 @@ | ||
async navigate(href: string): Promise<void> { | ||
async navigate( | ||
href: string, | ||
navigateAwayHandler = NAVIGATE_AWAY_HANDLER_DEFAULT, | ||
): Promise<void> { | ||
let originalHRef = href; | ||
let groups = /^([\w\d]+:)?\/\/([^/?]+)(.*)/.exec(href); | ||
if (groups) { | ||
let [, protocol, host, rest] = groups; | ||
if ( | ||
(protocol && protocol !== location.protocol) || | ||
host !== location.host | ||
) { | ||
navigateAwayHandler(originalHRef); | ||
return; | ||
} | ||
href = rest.startsWith('/') ? rest : `/${rest}`; | ||
} | ||
let prefix = this.prefix; | ||
if (/^[\w\d]+:\/\//.test(href) || !href.startsWith(prefix)) { | ||
location.href = href; | ||
if (!href.startsWith(prefix)) { | ||
navigateAwayHandler(originalHRef); | ||
return; | ||
@@ -201,0 +228,0 @@ } |
Sorry, the diff of this file is not supported yet
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
54739
1130