Skip to content

Commit 8dd9040

Browse files
committed
refactor: revert changes to path matching
1 parent 8baf28b commit 8dd9040

6 files changed

Lines changed: 51 additions & 61 deletions

File tree

app/components/ClaimPackageModal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ const connectorModalOpen = shallowRef(false)
192192

193193
<div class="flex gap-3">
194194
<NuxtLink
195-
:to="`/package/${packageName}`"
195+
:to="getPackageRoute(packageName)"
196196
class="flex-1 px-4 py-2 font-mono text-sm text-center text-bg bg-fg rounded-md transition-colors duration-200 hover:bg-fg/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
197197
@click="open = false"
198198
>
@@ -299,7 +299,7 @@ const connectorModalOpen = shallowRef(false)
299299
<span v-else class="w-4 h-4 shrink-0" />
300300
<div class="min-w-0">
301301
<NuxtLink
302-
:to="`/package/${pkg.name}`"
302+
:to="getPackageRoute(pkg.name)"
303303
class="font-mono text-sm text-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 rounded"
304304
target="_blank"
305305
>

app/components/HeaderPackagesDropdown.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function handleKeydown(event: KeyboardEvent) {
9494
<ul v-else-if="packages.length > 0" class="py-1 max-h-80 overflow-y-auto">
9595
<li v-for="pkg in packages" :key="pkg">
9696
<NuxtLink
97-
:to="`/${pkg}`"
97+
:to="getPackageRoute(pkg)"
9898
class="block px-3 py-2 font-mono text-sm text-fg hover:bg-bg-subtle transition-colors truncate"
9999
>
100100
{{ pkg }}

app/components/VersionSelector.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ watch(
625625
<!-- Link to package page for full version list -->
626626
<div class="border-t border-border mt-1 pt-1 px-3 py-2">
627627
<NuxtLink
628-
:to="`/${packageName}`"
628+
:to="getPackageRoute(packageName)"
629629
class="text-xs text-fg-subtle hover:text-fg transition-[color] focus-visible:outline-none focus-visible:text-fg"
630630
@click="isOpen = false"
631631
>

app/composables/usePackageRoute.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,12 @@
66
* @returns Route object with name and params
77
*/
88
export function getPackageRoute(pkg: string, version: string | null = null) {
9-
const [org, name] = pkg.startsWith('@') ? pkg.split('/') : [null, pkg]
10-
if (version) {
11-
return {
12-
name: 'package-version',
13-
params: { org, name, version },
14-
} as const
15-
}
16-
179
return {
1810
name: 'package',
1911
params: {
20-
org,
21-
name,
12+
package: [...pkg.split('/'), version ? 'v' : null, version].filter(
13+
(a): a is NonNullable<typeof a> => !!a,
14+
),
2215
},
2316
} as const
2417
}
@@ -36,17 +29,39 @@ export function getPackageRoute(pkg: string, version: string | null = null) {
3629
* @public
3730
*/
3831
export function usePackageRoute() {
39-
const route = useRoute('package-version')
32+
const route = useRoute('package')
33+
34+
const data = computed(() => {
35+
const segments = route.params.package || []
4036

41-
const orgName = computed(() => route.params.org)
42-
const requestedVersion = computed(() => route.params.version || null)
43-
const packageName = computed(() =>
44-
orgName.value ? `${orgName.value}/${route.params.name}` : route.params.name,
45-
)
37+
// Find the /v/ separator for version
38+
const vIndex = segments.indexOf('v')
39+
if (vIndex !== -1 && vIndex < segments.length - 1) {
40+
return {
41+
packageName: segments.slice(0, vIndex).join('/'),
42+
requestedVersion: segments.slice(vIndex + 1).join('/'),
43+
}
44+
}
45+
46+
// Parse @ versioned package
47+
const fullPath = segments.join('/')
48+
const versionMatch = fullPath.match(/^(@[^/]+\/[^/]+|[^/]+)@([^/]+)$/)
49+
if (versionMatch) {
50+
const [, packageName, requestedVersion] = versionMatch as [string, string, string]
51+
return {
52+
packageName,
53+
requestedVersion,
54+
}
55+
}
56+
57+
return {
58+
packageName: fullPath,
59+
requestedVersion: null as string | null,
60+
}
61+
})
4662

4763
return {
48-
packageName,
49-
requestedVersion,
50-
orgName,
64+
packageName: computed(() => data.value.packageName),
65+
requestedVersion: computed(() => data.value.requestedVersion),
5166
}
5267
}
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ import { areUrlsEquivalent } from '#shared/utils/url'
88
99
definePageMeta({
1010
name: 'package',
11+
alias: ['/package/:package(.*)*'],
1112
})
1213
1314
const router = useRouter()
1415
15-
const { packageName, requestedVersion, orgName } = usePackageRoute()
16+
const { packageName, requestedVersion } = usePackageRoute()
17+
18+
const orgName = computed(() => {
19+
const name = packageName.value
20+
if (!name.startsWith('@')) return null
21+
22+
const match = name.match(/^@([^/]+)\//)
23+
return match ? match[1] : null
24+
})
1625
1726
if (import.meta.server) {
1827
assertValidPackageName(packageName.value)
@@ -471,7 +480,7 @@ defineOgImageComponent('Package', {
471480

472481
<NuxtLink
473482
v-if="resolvedVersion !== requestedVersion"
474-
:to="`/${pkg.name}/v/${displayVersion.version}`"
483+
:to="getPackageRoute(pkg.name, displayVersion.version)"
475484
:title="$t('package.view_permalink')"
476485
>{{ displayVersion.version }}</NuxtLink
477486
>
@@ -992,7 +1001,7 @@ defineOgImageComponent('Package', {
9921001
>
9931002
<NuxtLink
9941003
v-if="typesPackageName"
995-
:to="`/${typesPackageName}`"
1004+
:to="getPackageRoute(typesPackageName)"
9961005
class="text-fg-subtle hover:text-fg-muted text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 rounded"
9971006
:title="$t('package.get_started.view_types', { package: typesPackageName })"
9981007
>
@@ -1076,7 +1085,7 @@ defineOgImageComponent('Package', {
10761085
}}</span>
10771086
</button>
10781087
<NuxtLink
1079-
:to="`/${createPackageInfo.packageName}`"
1088+
:to="getPackageRoute(createPackageInfo.packageName)"
10801089
class="text-fg-subtle hover:text-fg-muted text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 rounded"
10811090
:title="`View ${createPackageInfo.packageName}`"
10821091
>

modules/routing.ts

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

0 commit comments

Comments
 (0)