Skip to content

Commit ae1b7ff

Browse files
committed
feat: support 'strongMatching' option
1 parent f13a49f commit ae1b7ff

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ tree.matchPath('/admin'); // => { name: 'admin.home', params: {} }
9898
tree.buildPath('admin.home', {}, { trailingSlash: false }); // => '/admin'
9999
```
100100

101+
__Other options__
102+
103+
When matching paths, you can use two other options: `ignoreSearch` for not taking query parameters into account, and `strongMatching` (default `true`) for enforcing strong partial matching (making sure matches are well delimited).
101104

102105
## Callbacks
103106

modules/RouteNode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export default class RouteNode {
178178
}
179179

180180
getSegmentsMatchingPath(path, options) {
181-
const { trailingSlash, strictQueryParams } = options;
181+
const { trailingSlash, strictQueryParams, strongMatching } = options;
182182
let matchChildren = (nodes, pathSegment, segments) => {
183183
const isRoot = nodes.length === 1 && nodes[0].name === '';
184184
// for (child of node.children) {
@@ -194,7 +194,7 @@ export default class RouteNode {
194194
}
195195

196196
if (!match) {
197-
match = child.parser.partialTest(pathSegment);
197+
match = child.parser.partialTest(pathSegment, { delimiter: strongMatching });
198198
}
199199

200200
if (match) {
@@ -365,7 +365,7 @@ export default class RouteNode {
365365
}
366366

367367
matchPath(path, options) {
368-
const defaultOptions = { trailingSlash: false, strictQueryParams: true };
368+
const defaultOptions = { trailingSlash: false, strictQueryParams: true, strongMatching: true };
369369
const opts = { ...defaultOptions, ...options };
370370
let matchedSegments = this.getSegmentsMatchingPath(path, opts);
371371

0 commit comments

Comments
 (0)