diff --git a/src/codegen/generateRouteRecords.spec.ts b/src/codegen/generateRouteRecords.spec.ts index 738027b30..ba7f64b3d 100644 --- a/src/codegen/generateRouteRecords.spec.ts +++ b/src/codegen/generateRouteRecords.spec.ts @@ -4,6 +4,7 @@ import { PrefixTree, TreeNode } from '../core/tree' import { resolveOptions } from '../options' import { generateRouteRecord } from './generateRouteRecords' import { ImportsMap } from '../core/utils' +import { join } from 'path' const DEFAULT_OPTIONS = resolveOptions({}) @@ -339,5 +340,28 @@ describe('generateRouteRecord', () => { // what matters is that the import name is reused _page_0 expect(generateRouteRecordSimple(tree)).toMatchSnapshot() }) + it('dedupes sync imports for the same component', () => { + const tree = new PrefixTree( + resolveOptions({ + importMode: 'sync', + }) + ) + + tree.insertParsedPath('a/b', 'a.vue') + tree.insertParsedPath('a/c', 'a.vue') + + // what matters is that the import name is reused _page_0 + expect(generateRouteRecordSimple(tree)).toMatchSnapshot() + }) + it.runIf(process.platform === "win32")('path style should be normalized with Posix style', () => { + const tree = new PrefixTree( + resolveOptions({ + importMode: 'async', + }) + ) + tree.insert('from-root', join(__dirname, './src/pages/index.vue')) + tree.insert('from-root2', join("\\unplugin-vue-router\\", './src/pages/index.vue')) + expect(generateRouteRecordSimple(tree)).not.toContain("\\") + }) }) }) diff --git a/src/codegen/generateRouteRecords.ts b/src/codegen/generateRouteRecords.ts index 2b064d3a1..60c2861cb 100644 --- a/src/codegen/generateRouteRecords.ts +++ b/src/codegen/generateRouteRecords.ts @@ -1,3 +1,4 @@ +import { normalize } from 'pathe' import type { TreeNode } from '../core/tree' import { ImportsMap } from '../core/utils' import { type ResolvedOptions } from '../options' @@ -137,6 +138,9 @@ function generatePageImport( importMode: ResolvedOptions['importMode'], importsMap: ImportsMap ) { + if (process.platform === 'win32') { + filepath = normalize(filepath) + } const mode = typeof importMode === 'function' ? importMode(filepath) : importMode if (mode === 'async') {