Skip to content

Commit 9c798ad

Browse files
authored
refactor: migrate to unrouting (#3931)
1 parent e6d3bd2 commit 9c798ad

File tree

5 files changed

+25
-197
lines changed

5 files changed

+25
-197
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"ufo": "^1.6.1",
9898
"unplugin": "^2.3.11",
9999
"unplugin-vue-router": "^0.16.0",
100+
"unrouting": "^0.1.5",
100101
"unstorage": "^1.16.1",
101102
"vue-i18n": "^11.1.11",
102103
"vue-router": "^4.6.4"

pnpm-lock.yaml

Lines changed: 12 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isString } from '@intlify/shared'
44
import { parse as parseSFC } from '@vue/compiler-sfc'
55
import { parseAndWalk } from 'oxc-walker'
66
import { mkdir, readFile, writeFile } from 'node:fs/promises'
7-
import { getRoutePath, parseSegment } from './utils/route-parsing'
7+
import { parseSegment, toVueRouterSegment } from 'unrouting'
88
import { localizeRoutes } from './routing'
99
import { dirname, parse as parsePath, resolve } from 'pathe'
1010
import { createRoutesContext } from 'unplugin-vue-router'
@@ -295,7 +295,7 @@ export function getRouteOptionsResolver(
295295

296296
function resolveRoutePath(path: string): string {
297297
const tokens = parseSegment(path.slice(1))
298-
return getRoutePath(tokens)
298+
return '/' + toVueRouterSegment(tokens)
299299
}
300300

301301
function getRouteFromConfig(

src/utils/route-parsing.ts

Lines changed: 0 additions & 155 deletions
This file was deleted.

test/utils.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { resolveLocales } from '../src/utils'
2-
import { parseSegment, getRoutePath } from '../src/utils/route-parsing'
2+
import { parseSegment, toVueRouterSegment } from 'unrouting'
33
import type { LocaleObject } from '../src/types'
44
import { vi, beforeEach, afterEach, test, expect, beforeAll } from 'vitest'
55

@@ -132,17 +132,17 @@ test('resolveLocales', async () => {
132132
test('parseSegment', () => {
133133
const tokens = parseSegment('[foo]_[bar]:[...buz]_buz_[[qux]]')
134134
expect(tokens).toEqual([
135-
{ type: 1, value: 'foo' },
136-
{ type: 0, value: '_' },
137-
{ type: 1, value: 'bar' },
138-
{ type: 0, value: ':' },
139-
{ type: 3, value: 'buz' },
140-
{ type: 0, value: '_buz_' },
141-
{ type: 2, value: 'qux' }
135+
{ type: 'dynamic', value: 'foo' },
136+
{ type: 'static', value: '_' },
137+
{ type: 'dynamic', value: 'bar' },
138+
{ type: 'static', value: ':' },
139+
{ type: 'catchall', value: 'buz' },
140+
{ type: 'static', value: '_buz_' },
141+
{ type: 'optional', value: 'qux' },
142142
])
143143
})
144144

145-
test('getRoutePath', () => {
145+
test('toVueRouterSegment', () => {
146146
const tokens = parseSegment('[foo]_[bar]:[...buz]_buz_[[qux]]')
147-
expect(getRoutePath(tokens)).toBe(`/:foo()_:bar()\\::buz(.*)*_buz_:qux?`)
147+
expect('/' + toVueRouterSegment(tokens)).toBe(`/:foo()_:bar()\\::buz(.*)*_buz_:qux?`)
148148
})

0 commit comments

Comments
 (0)