mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
Fix some router issues
- Clicking on the project in various places goes now to `../<rid>` instead of `../<rid>/tree/<commit>` - Project URL on seed allows trailing slash, eg. `../<rid>/` - Navigating to a project URL with a `remotes/<nodeId>` suffix works now correctly w or w/o trailing slash Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
+10
-3
@@ -153,7 +153,11 @@ function pathToRoute(path: string): Route | null {
|
||||
if (host) {
|
||||
const id = segments.shift();
|
||||
if (id) {
|
||||
if (segments.length === 0) {
|
||||
// Allows project paths with or without trailing slash
|
||||
if (
|
||||
segments.length === 0 ||
|
||||
(segments.length === 1 && segments[0] === "")
|
||||
) {
|
||||
return {
|
||||
resource: "projects",
|
||||
params: {
|
||||
@@ -247,7 +251,10 @@ export function routeToPath(route: Route) {
|
||||
}
|
||||
|
||||
if (route.params.view.resource === "tree") {
|
||||
return `${hostPrefix}/${route.params.id}${peer}/tree${suffix}`;
|
||||
if (suffix) {
|
||||
return `${hostPrefix}/${route.params.id}${peer}/tree${suffix}`;
|
||||
}
|
||||
return `${hostPrefix}/${route.params.id}${peer}`;
|
||||
} else if (route.params.view.resource === "commits") {
|
||||
return `${hostPrefix}/${route.params.id}${peer}/commits${suffix}`;
|
||||
} else if (route.params.view.resource === "history") {
|
||||
@@ -284,7 +291,7 @@ function resolveProjectRoute(
|
||||
content = segments.shift();
|
||||
}
|
||||
|
||||
if (content === "tree") {
|
||||
if (!content || content === "tree") {
|
||||
const line = url.href.match(/#L\d+$/)?.pop();
|
||||
const hash = url.href.match(/#{1}[^#.]+$/)?.pop();
|
||||
return {
|
||||
|
||||
@@ -36,9 +36,9 @@
|
||||
params: {
|
||||
view: { resource: "tree" },
|
||||
id: project.id,
|
||||
peer: undefined,
|
||||
seed: seed.host,
|
||||
revision: project.head ?? undefined,
|
||||
peer: undefined,
|
||||
revision: undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
seed.addr.port === config.seeds.defaultHttpdPort
|
||||
? seed.addr.host
|
||||
: `${seed.addr.host}:${seed.addr.port}`,
|
||||
revision: project.head ?? undefined,
|
||||
revision: undefined,
|
||||
hash: undefined,
|
||||
search: undefined,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user