Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ export class PageContext {
}

async mergePageMetaData() {
// 收集所有子包中的页面绝对路径
const subPageAbsolutePaths = Array.from(this.subPages.values()).flatMap(v => Array.from(v.keys()))

// 过滤掉属于子包的页面
for (const subPageAbsolutePath of subPageAbsolutePaths)
this.pages.delete(subPageAbsolutePath)

const pageMetaData = await this.parsePages(this.pages, 'main', this.pagesGlobConfig?.pages)

this.pageMetaData = pageMetaData
Expand Down
5 changes: 5 additions & 0 deletions packages/playground/src/pages/pages-internal-sub/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
this is pages-internal-sub
</div>
</template>
3 changes: 2 additions & 1 deletion packages/playground/src/uni-pages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ type _LocationUrl =
"/pages/define-page/yaml" |
"/pages-sub/index" |
"/pages-sub/about/index" |
"/pages-sub/about/your";
"/pages-sub/about/your" |
"/pages/pages-internal-sub/index";

interface NavigateToOptions {
url: _LocationUrl;
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default defineConfig({
dts: 'src/uni-pages.d.ts',
homePage: 'pages/index',
debug: true,
subPackages: ['src/pages-sub', 'src/pages-sub2'],
subPackages: ['src/pages-sub', 'src/pages-sub2', 'src/pages/pages-internal-sub'],
// configSource: [
// {
// files: 'vite.config',
Expand Down
1 change: 1 addition & 0 deletions test/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('get files', () => {
"i18n.vue",
"index.nvue",
"index.vue",
"pages-internal-sub/index.vue",
"test-json.vue",
"test-jsonc-with-comment.vue",
"test-yaml.vue",
Expand Down
7 changes: 5 additions & 2 deletions test/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ const pagesGlobConfig: UserPagesConfig = {

describe('generate routes', () => {
it('vue - pages snapshot', async () => {
const ctx = new PageContext({ dir: 'packages/playground/src/pages', homePage: 'pages/index' })
const ctx = new PageContext({ dir: 'packages/playground/src/pages', homePage: 'pages/index', subPackages: ['packages/playground/src/pages/pages-internal-sub'] })
await ctx.scanPages()
await ctx.scanSubPages()
await ctx.mergePageMetaData()

const routes = ctx.resolveRoutes()

expect(routes).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -173,9 +175,10 @@ describe('generate routes', () => {
})

it('vue - not merge pages snapshot', async () => {
const ctx = new PageContext({ dir: 'packages/playground/src/pages', mergePages: false })
const ctx = new PageContext({ dir: 'packages/playground/src/pages', mergePages: false, subPackages: ['packages/playground/src/pages/pages-internal-sub'] })
await ctx.scanPages()
ctx.pagesGlobConfig = pagesGlobConfig
await ctx.scanSubPages()
await ctx.mergePageMetaData()
const routes = ctx.resolveRoutes()

Expand Down