Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

boring-router-react

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boring-router-react - npm Package Compare versions

Comparing version 0.3.8 to 0.3.9

3

bld/library/browser-history.d.ts
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc