|
1 | 1 | import { describe, it, expect } from 'vitest' |
2 | 2 | import { createRouteResourcesCollector, localizeRoutes } from '../../src/routing' |
3 | 3 | import { localizeSingleRoute, createRouteContext, canCompactRoute } from '../../src/kit/gen' |
4 | | -import { collectCompactPrerenderRoutes } from '../../src/pages' |
| 4 | +import { collectCompactPrerenderRoutes, createPureOptionsResolver, NuxtPageAnalyzeContext } from '../../src/pages' |
5 | 5 | import { createMockOptionsResolver, createTestConfig, getNormalizedLocales } from './utils' |
6 | 6 |
|
7 | 7 | import type { LocalizableRoute, LocalizeRouteParams } from '../../src/kit/gen' |
@@ -639,6 +639,54 @@ describe('createRouteResourcesCollector', () => { |
639 | 639 | }) |
640 | 640 | }) |
641 | 641 |
|
| 642 | +// nuxt injects stub pages for `routeRules` redirects, the rules only match unprefixed paths (#3606) |
| 643 | +describe.each([false, true])('routeRules redirect stubs (compactRoutes: %s)', (compactRoutes) => { |
| 644 | + const stubFile = '/app/node_modules/nuxt/dist/pages/runtime/component-stub' |
| 645 | + |
| 646 | + function makeConfig(resolver: ReturnType<typeof createPureOptionsResolver>) { |
| 647 | + return createTestConfig({ |
| 648 | + locales: ['en', 'fr'], |
| 649 | + strategy: 'prefix_except_default', |
| 650 | + defaultLocale: 'en', |
| 651 | + optionsResolver: resolver, |
| 652 | + compactRoutes, |
| 653 | + }) |
| 654 | + } |
| 655 | + |
| 656 | + it('passes stubs through unlocalized and keeps them out of route resources', () => { |
| 657 | + const resolver = createPureOptionsResolver(new NuxtPageAnalyzeContext({}), 'en', 'config', stubFile) |
| 658 | + const collector = createRouteResourcesCollector() |
| 659 | + const result = localizeRoutes( |
| 660 | + [ |
| 661 | + { path: '/about', name: 'about', file: '/pages/about.vue' }, |
| 662 | + { _sync: true, path: '/old-path', file: `${stubFile}.js` }, |
| 663 | + ], |
| 664 | + { ...makeConfig(resolver), onLocalize: collector.collect }, |
| 665 | + ) |
| 666 | + |
| 667 | + const stubs = result.filter(r => r.path.includes('old-path')) |
| 668 | + expect(stubs).toHaveLength(1) |
| 669 | + expect(stubs[0]!.path).toBe('/old-path') |
| 670 | + expect(result.find(r => r.path === (compactRoutes ? '/:locale(fr)/about' : '/fr/about'))).toBeDefined() |
| 671 | + |
| 672 | + const resources = collector.toResources() |
| 673 | + expect(resources.localizedPaths).not.toContain('/old-path') |
| 674 | + expect(resources.disabledPaths).not.toContain('/old-path') |
| 675 | + }) |
| 676 | + |
| 677 | + it('does not skip a project page named component-stub', () => { |
| 678 | + const resolver = createPureOptionsResolver(new NuxtPageAnalyzeContext({}), 'en', 'config', stubFile) |
| 679 | + const result = localizeRoutes( |
| 680 | + [{ path: '/runtime/component-stub', name: 'stub-page', file: '/pages/runtime/component-stub.vue' }], |
| 681 | + makeConfig(resolver), |
| 682 | + ) |
| 683 | + expect(result.find(r => r.name === 'stub-page___en')).toBeDefined() |
| 684 | + expect( |
| 685 | + result.find(r => r.path === (compactRoutes ? '/:locale(fr)/runtime/component-stub' : '/fr/runtime/component-stub')), |
| 686 | + ).toBeDefined() |
| 687 | + }) |
| 688 | +}) |
| 689 | + |
642 | 690 | // --------------------------------------------------------------------------- |
643 | 691 | // e) canCompactRoute |
644 | 692 | // --------------------------------------------------------------------------- |
|
0 commit comments