Skip to content

Commit a245a2b

Browse files
committed
removed non-legacy code from exact-match; updated navigateToRoute helper to infer router mode from page
1 parent dfbf77f commit a245a2b

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/core/virtual-routes/exact-match.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
* @returns {string}
55
*/
66
export function makeExactMatcher(matcher) {
7-
const matcherWithBeginningOfInput = matcher.startsWith('^')
8-
? matcher
9-
: `^${matcher}`;
7+
const matcherWithBeginningOfInput =
8+
matcher.slice(0, 1) === '^' ? matcher : `^${matcher}`;
109

1110
const matcherWithBeginningAndEndOfInput =
12-
matcherWithBeginningOfInput.endsWith('$')
11+
matcherWithBeginningOfInput.slice(-1) === '$'
1312
? matcherWithBeginningOfInput
1413
: `${matcherWithBeginningOfInput}$`;
1514

test/helpers/navigate.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* Navigate to a specific route in the site
33
* @param {import('playwright-core').Page} page the playwright page instance from the test
44
* @param {string} route the route you want to navigate to
5-
* @param {Object} opts additional options (optional)
6-
* @param {'hash' | 'history'} opts.routerMode which router mode to use. Defaults to "hash"
75
*/
86

9-
async function navigateToRoute(page, route, { routerMode = 'hash' } = {}) {
10-
if (routerMode === 'hash') {
11-
await page.evaluate(r => (window.location.hash = r), route);
12-
} else {
7+
async function navigateToRoute(page, route) {
8+
const routerMode = await page.evaluate(() => window.$docsify.routerMode);
9+
10+
if (routerMode === 'history') {
1311
await page.evaluate(r => window.history.pushState({ key: r }, '', r));
12+
} else {
13+
await page.evaluate(r => (window.location.hash = r), route);
1414
}
1515

1616
await page.waitForLoadState('networkidle');

0 commit comments

Comments
 (0)