diff --git a/lib/app/util.js b/lib/app/util.js index 0481dfec30..0fe673b20e 100644 --- a/lib/app/util.js +++ b/lib/app/util.js @@ -1,3 +1,9 @@ +export function ensureEndingSlash (path) { + return /(\.html|\/)$/.test(path) + ? path + : path + '/' +} + export function pathToComponentName (path) { if (path.charAt(path.length - 1) === '/') { return `page${path.replace(/\//g, '-') + 'index'}` @@ -9,7 +15,7 @@ export function pathToComponentName (path) { export function findPageForPath (pages, path) { for (let i = 0; i < pages.length; i++) { const page = pages[i] - if (page.path === path) { + if (page.path === ensureEndingSlash(path)) { return page } } diff --git a/lib/default-theme/util.js b/lib/default-theme/util.js index e5a859be25..1725155be6 100644 --- a/lib/default-theme/util.js +++ b/lib/default-theme/util.js @@ -1,3 +1,5 @@ +import { ensureEndingSlash } from '../app/util' + export const hashRE = /#.*$/ export const extRE = /\.(md|html)$/ export const endingSlashRE = /\/$/ @@ -184,12 +186,6 @@ export function resolveMatchingConfig (route, config) { return {} } -function ensureEndingSlash (path) { - return /(\.html|\/)$/.test(path) - ? path - : path + '/' -} - function resolveItem (item, pages, base, isNested) { if (typeof item === 'string') { return resolvePage(pages, item, base)