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

@aurelia/router-lite

Package Overview
Dependencies
Maintainers
1
Versions
264
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aurelia/router-lite - npm Package Compare versions

Comparing version 2.1.0-dev.202206080345 to 2.1.0-dev.202206150910

2

dist/types/index.d.ts

@@ -5,3 +5,3 @@ export { type IViewport, } from './resources/viewport';

export { type RouteableComponent, type NavigationInstruction, IViewportInstruction, type Params, } from './instructions';
export { ILocationManager, IBaseHrefProvider, } from './location-manager';
export { ILocationManager, } from './location-manager';
export { type Routeable, type IRouteConfig, type IChildRouteConfig, RouteConfig, Route, type RouteType, route, } from './route';

@@ -8,0 +8,0 @@ export { IRouteContext, RouteContext, type INavigationModel, type INavigationRoute, } from './route-context';

@@ -8,22 +8,3 @@ import { ILogger } from '@aurelia/kernel';

}
export declare const IBaseHrefProvider: import("@aurelia/kernel").InterfaceSymbol<IBaseHrefProvider>;
export interface IBaseHrefProvider extends BrowserBaseHrefProvider {
}
export declare class BaseHref {
readonly path: string;
readonly rootedPath: string;
constructor(path: string, rootedPath: string);
}
/**
* Default browser base href provider.
*
* Retrieves the base href based on the `<base>` element from `window.document.head`
*
* This is internal API for the moment. The shape of this API (as well as in which package it resides) is also likely temporary.
*/
export declare class BrowserBaseHrefProvider {
private readonly window;
constructor(window: IWindow);
getBaseHref(): BaseHref | null;
}
export declare const IBaseHref: import("@aurelia/kernel").InterfaceSymbol<URL>;
export declare const ILocationManager: import("@aurelia/kernel").InterfaceSymbol<ILocationManager>;

@@ -45,6 +26,5 @@ export interface ILocationManager extends BrowserLocationManager {

private readonly window;
private readonly baseHrefProvider;
private readonly baseHref;
private eventId;
constructor(logger: ILogger, events: IRouterEvents, history: IHistory, location: ILocation, window: IWindow, baseHrefProvider: IBaseHrefProvider);
constructor(logger: ILogger, events: IRouterEvents, history: IHistory, location: ILocation, window: IWindow, baseHref: URL);
startListening(): void;

@@ -61,2 +41,6 @@ stopListening(): void;

}
/**
* Strip trailing `/index.html` and trailing `/` from the path, if present.
*/
export declare function normalizePath(path: string): string;
//# sourceMappingURL=location-manager.d.ts.map

@@ -26,2 +26,7 @@ import { IContainer, ILogger } from '@aurelia/kernel';

export interface IRouterOptions extends Partial<RouterOptions> {
/**
* Set a custom routing root by setting this path.
* When not set, path from the `document.baseURI` is used by default.
*/
basePath?: string | null;
}

@@ -28,0 +33,0 @@ export declare class RouterOptions {

{
"name": "@aurelia/router-lite",
"version": "2.1.0-dev.202206080345",
"version": "2.1.0-dev.202206150910",
"main": "dist/cjs/index.cjs",

@@ -47,9 +47,9 @@ "module": "dist/esm/index.mjs",

"dependencies": {
"@aurelia/kernel": "2.1.0-dev.202206080345",
"@aurelia/metadata": "2.1.0-dev.202206080345",
"@aurelia/platform": "2.1.0-dev.202206080345",
"@aurelia/platform-browser": "2.1.0-dev.202206080345",
"@aurelia/route-recognizer": "2.1.0-dev.202206080345",
"@aurelia/runtime": "2.1.0-dev.202206080345",
"@aurelia/runtime-html": "2.1.0-dev.202206080345"
"@aurelia/kernel": "2.1.0-dev.202206150910",
"@aurelia/metadata": "2.1.0-dev.202206150910",
"@aurelia/platform": "2.1.0-dev.202206150910",
"@aurelia/platform-browser": "2.1.0-dev.202206150910",
"@aurelia/route-recognizer": "2.1.0-dev.202206150910",
"@aurelia/runtime": "2.1.0-dev.202206150910",
"@aurelia/runtime-html": "2.1.0-dev.202206150910"
},

@@ -56,0 +56,0 @@ "devDependencies": {

import { isObject } from '@aurelia/metadata';
import { IContainer, IRegistry } from '@aurelia/kernel';
import { AppTask } from '@aurelia/runtime-html';
import { IContainer, InterfaceSymbol, IRegistry, Registration } from '@aurelia/kernel';
import { AppTask, AppTaskCallback, IWindow } from '@aurelia/runtime-html';

@@ -11,2 +11,3 @@ import { RouteContext } from './route-context';

import { HrefCustomAttribute } from './resources/href';
import { IBaseHref, normalizePath } from './location-manager';

@@ -46,14 +47,23 @@ export const RouterRegistration = IRouter as unknown as IRegistry;

function configure(container: IContainer, config?: RouterConfig): IContainer {
let activation: AppTaskCallback<InterfaceSymbol<IRouter>>;
let basePath: string | null = null;
if (isObject(config)) {
if (typeof config === 'function') {
activation = router => config(router) as void | Promise<void>;
} else {
basePath = (config as IRouterOptions).basePath ?? null;
activation = router => router.start(config, true) as void | Promise<void>;
}
} else {
activation = router => router.start({}, true) as void | Promise<void>;
}
return container.register(
Registration.cachedCallback(IBaseHref, (handler, _, __) => {
const window = handler.get(IWindow);
const url = new URL(window.document.baseURI);
url.pathname = normalizePath(basePath ?? url.pathname);
return url;
}),
AppTask.hydrated(IContainer, RouteContext.setRoot),
AppTask.afterActivate(IRouter, router => {
if (isObject(config)) {
if (typeof config === 'function') {
return config(router) as void | Promise<void>;
} else {
return router.start(config, true) as void | Promise<void>;
}
}
return router.start({}, true) as void | Promise<void>;
}),
AppTask.afterActivate(IRouter, activation),
AppTask.afterDeactivate(IRouter, router => {

@@ -60,0 +70,0 @@ router.stop();

@@ -32,3 +32,2 @@ export {

ILocationManager,
IBaseHrefProvider,
} from './location-manager';

@@ -35,0 +34,0 @@

@@ -1,2 +0,2 @@

import { ILogger, DI, bound } from '@aurelia/kernel';
import { bound, DI, ILogger } from '@aurelia/kernel';
import { IHistory, ILocation, IWindow } from '@aurelia/runtime-html';

@@ -9,36 +9,3 @@

export const IBaseHrefProvider = DI.createInterface<IBaseHrefProvider>('IBaseHrefProvider', x => x.singleton(BrowserBaseHrefProvider));
export interface IBaseHrefProvider extends BrowserBaseHrefProvider {}
export class BaseHref {
public constructor(
public readonly path: string,
public readonly rootedPath: string,
) {}
}
/**
* Default browser base href provider.
*
* Retrieves the base href based on the `<base>` element from `window.document.head`
*
* This is internal API for the moment. The shape of this API (as well as in which package it resides) is also likely temporary.
*/
export class BrowserBaseHrefProvider {
public constructor(
@IWindow private readonly window: IWindow,
) {}
public getBaseHref(): BaseHref | null {
const base = this.window.document.head.querySelector('base');
if (base === null) {
return null;
}
const rootedPath = normalizePath(base.href);
const path = normalizePath(base.getAttribute('href') ?? '');
return new BaseHref(path, rootedPath);
}
}
export const IBaseHref = DI.createInterface<URL>('IBaseHref');
export const ILocationManager = DI.createInterface<ILocationManager>('ILocationManager', x => x.singleton(BrowserLocationManager));

@@ -55,3 +22,2 @@ export interface ILocationManager extends BrowserLocationManager {}

export class BrowserLocationManager {
private readonly baseHref: BaseHref;
private eventId: number = 0;

@@ -65,15 +31,6 @@

@IWindow private readonly window: IWindow,
@IBaseHrefProvider private readonly baseHrefProvider: IBaseHrefProvider,
@IBaseHref private readonly baseHref: URL,
) {
this.logger = logger.root.scopeTo('LocationManager');
const baseHref = baseHrefProvider.getBaseHref();
if (baseHref === null) {
const origin = location.origin ?? '';
const baseHref = this.baseHref = new BaseHref('', normalizePath(origin));
this.logger.warn(`no baseHref provided, defaulting to origin '${baseHref.rootedPath}' (normalized from '${origin}')`);
} else {
this.baseHref = baseHref;
this.logger.debug(`baseHref set to path: '${baseHref.path}', rootedPath: '${baseHref.rootedPath}'`);
}
logger = this.logger = logger.root.scopeTo('LocationManager');
logger.debug(`baseHref set to path: ${baseHref.href}`);
}

@@ -164,3 +121,3 @@

let base = this.baseHref.rootedPath;
let base = this.baseHref.href;
if (base.endsWith('/')) {

@@ -186,4 +143,5 @@ base = base.slice(0, -1);

const $path = path;
if (path.startsWith(this.baseHref.path)) {
path = path.slice(this.baseHref.path.length);
const basePath = this.baseHref.pathname;
if (path.startsWith(basePath)) {
path = path.slice(basePath.length);
}

@@ -201,3 +159,3 @@ path = normalizePath(path);

*/
function normalizePath(path: string): string {
export function normalizePath(path: string): string {
let start: string;

@@ -204,0 +162,0 @@ let end: string;

@@ -44,3 +44,9 @@ import { isObject } from '@aurelia/metadata';

export interface IRouterOptions extends Partial<RouterOptions> { }
export interface IRouterOptions extends Partial<RouterOptions> {
/**
* Set a custom routing root by setting this path.
* When not set, path from the `document.baseURI` is used by default.
*/
basePath?: string | null;
}
export class RouterOptions {

@@ -47,0 +53,0 @@ public static get DEFAULT(): RouterOptions { return RouterOptions.create({}); }

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 not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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