boring-router
Advanced tools
Comparing version 0.3.0-alpha.38 to 0.3.0-alpha.39
@@ -42,3 +42,4 @@ "use strict"; | ||
if (index < 0) { | ||
throw new Error('Invalid history snapshot'); | ||
console.error('Invalid history snapshot'); | ||
return entries.length - 1; | ||
} | ||
@@ -51,7 +52,7 @@ return index; | ||
if (!entry) { | ||
throw new Error('Invalid history snapshot'); | ||
console.error('Invalid history snapshot'); | ||
} | ||
return entry; | ||
return entries[entries.length - 1]; | ||
} | ||
exports.getActiveHistoryEntry = getActiveHistoryEntry; | ||
//# sourceMappingURL=history.js.map |
@@ -47,2 +47,5 @@ "use strict"; | ||
get $rest() { | ||
if (!this.$matched || this.$exact) { | ||
return this; | ||
} | ||
let children = this._children; | ||
@@ -49,0 +52,0 @@ let matchingChild = children && children.find(match => match.$matched); |
@@ -85,3 +85,3 @@ import { OmitValueOfKey, OmitValueWithType } from 'tslang'; | ||
export interface RouteMatchOptions extends RouteMatchSharedOptions { | ||
exact: boolean; | ||
exact: boolean | string; | ||
} | ||
@@ -88,0 +88,0 @@ export declare class RouteMatch<TParamDict extends GeneralParamDict = GeneralParamDict, TNextRouteMatch extends NextRouteMatch<TParamDict> = NextRouteMatch<TParamDict>, TSpecificGroupName extends string | undefined = string | undefined, TGroupName extends string = string> extends RouteMatchShared<TParamDict, TSpecificGroupName, TGroupName> { |
@@ -210,5 +210,11 @@ "use strict"; | ||
let exactlyMatched = matched && rest === ''; | ||
if (exactlyMatched && (this._children && !this._allowExact)) { | ||
matched = false; | ||
exactlyMatched = false; | ||
if (exactlyMatched) { | ||
let allowExact = this._allowExact; | ||
if (typeof allowExact === 'string') { | ||
rest = `/${allowExact}`; | ||
} | ||
else if (this._children && !allowExact) { | ||
matched = false; | ||
exactlyMatched = false; | ||
} | ||
} | ||
@@ -215,0 +221,0 @@ return { |
@@ -72,3 +72,3 @@ "use strict"; | ||
let routeMatch = groupToRouteMatchMap.get(group); | ||
let routeMatchEntries = this._routerMatch(routeMatch ? [routeMatch] : [], path) || []; | ||
let routeMatchEntries = this._match(routeMatch ? [routeMatch] : [], path) || []; | ||
if (!routeMatchEntries.length) { | ||
@@ -321,3 +321,3 @@ continue; | ||
/** @internal */ | ||
_routerMatch(routeMatches, upperRest) { | ||
_match(routeMatches, upperRest) { | ||
for (let routeMatch of routeMatches) { | ||
@@ -328,3 +328,3 @@ let { matched, exactlyMatched, segment, rest } = routeMatch._match(upperRest); | ||
} | ||
if (exactlyMatched) { | ||
if (rest === '') { | ||
return [ | ||
@@ -334,3 +334,3 @@ { | ||
segment: segment, | ||
exact: true, | ||
exact: exactlyMatched, | ||
rest, | ||
@@ -340,3 +340,3 @@ }, | ||
} | ||
let result = this._routerMatch(routeMatch._children || [], rest); | ||
let result = this._match(routeMatch._children || [], rest); | ||
if (!result) { | ||
@@ -349,3 +349,3 @@ continue; | ||
segment: segment, | ||
exact: false, | ||
exact: exactlyMatched, | ||
rest, | ||
@@ -352,0 +352,0 @@ }, |
@@ -8,4 +8,7 @@ import { Dict } from 'tslang'; | ||
* applies if this route has children. | ||
* | ||
* If a string is applied, it will try to match the children when the current | ||
* route is exactly matched. | ||
*/ | ||
$exact?: boolean; | ||
$exact?: boolean | string; | ||
$children?: RouteSchemaDict; | ||
@@ -12,0 +15,0 @@ $extension?: object; |
{ | ||
"name": "boring-router", | ||
"version": "0.3.0-alpha.38", | ||
"version": "0.3.0-alpha.39", | ||
"description": "A light-weight, type-safe, yet reactive router service using MobX.", | ||
@@ -40,3 +40,3 @@ "repository": { | ||
}, | ||
"gitHead": "967f6cb251a3bc95ab26ac19cc975b452ce411a4" | ||
"gitHead": "c4334477fcff522e5941726d008ea6f63ee68f26" | ||
} |
@@ -91,3 +91,4 @@ export type HistoryChangeCallbackRemovalHandler = () => void; | ||
if (index < 0) { | ||
throw new Error('Invalid history snapshot'); | ||
console.error('Invalid history snapshot'); | ||
return entries.length - 1; | ||
} | ||
@@ -105,6 +106,6 @@ | ||
if (!entry) { | ||
throw new Error('Invalid history snapshot'); | ||
console.error('Invalid history snapshot'); | ||
} | ||
return entry; | ||
return entries[entries.length - 1]; | ||
} |
@@ -140,2 +140,6 @@ import {computed} from 'mobx'; | ||
get $rest(): this { | ||
if (!this.$matched || this.$exact) { | ||
return this; | ||
} | ||
let children = this._children; | ||
@@ -142,0 +146,0 @@ |
@@ -177,3 +177,3 @@ import {observable} from 'mobx'; | ||
export interface RouteMatchOptions extends RouteMatchSharedOptions { | ||
exact: boolean; | ||
exact: boolean | string; | ||
} | ||
@@ -222,3 +222,3 @@ | ||
/** @internal */ | ||
private _allowExact: boolean; | ||
private _allowExact: boolean | string; | ||
@@ -506,5 +506,11 @@ /** @internal */ | ||
if (exactlyMatched && (this._children && !this._allowExact)) { | ||
matched = false; | ||
exactlyMatched = false; | ||
if (exactlyMatched) { | ||
let allowExact = this._allowExact; | ||
if (typeof allowExact === 'string') { | ||
rest = `/${allowExact}`; | ||
} else if (this._children && !allowExact) { | ||
matched = false; | ||
exactlyMatched = false; | ||
} | ||
} | ||
@@ -511,0 +517,0 @@ |
@@ -202,3 +202,3 @@ import hyphenate from 'hyphenate'; | ||
match: string | symbol | RegExp; | ||
exact: boolean; | ||
exact: boolean | string; | ||
query: Dict<boolean> | undefined; | ||
@@ -453,3 +453,3 @@ children: RouteSchemaDict | undefined; | ||
let routeMatchEntries = | ||
this._routerMatch(routeMatch ? [routeMatch] : [], path) || []; | ||
this._match(routeMatch ? [routeMatch] : [], path) || []; | ||
@@ -713,3 +713,3 @@ if (!routeMatchEntries.length) { | ||
/** @internal */ | ||
private _routerMatch( | ||
private _match( | ||
routeMatches: RouteMatch[], | ||
@@ -727,3 +727,3 @@ upperRest: string, | ||
if (exactlyMatched) { | ||
if (rest === '') { | ||
return [ | ||
@@ -733,3 +733,3 @@ { | ||
segment: segment!, | ||
exact: true, | ||
exact: exactlyMatched, | ||
rest, | ||
@@ -740,3 +740,3 @@ }, | ||
let result = this._routerMatch(routeMatch._children || [], rest); | ||
let result = this._match(routeMatch._children || [], rest); | ||
@@ -751,3 +751,3 @@ if (!result) { | ||
segment: segment!, | ||
exact: false, | ||
exact: exactlyMatched, | ||
rest, | ||
@@ -754,0 +754,0 @@ }, |
@@ -9,4 +9,7 @@ import {Dict} from 'tslang'; | ||
* applies if this route has children. | ||
* | ||
* If a string is applied, it will try to match the children when the current | ||
* route is exactly matched. | ||
*/ | ||
$exact?: boolean; | ||
$exact?: boolean | string; | ||
$children?: RouteSchemaDict; | ||
@@ -13,0 +16,0 @@ $extension?: object; |
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
176326
56
3818