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:
Sebastian Martinez
2023-03-07 12:53:17 +01:00
parent 742fe4dec0
commit 2498ef7c9e
7 changed files with 54 additions and 30 deletions
+10 -3
View File
@@ -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 {
+2 -2
View File
@@ -36,9 +36,9 @@
params: {
view: { resource: "tree" },
id: project.id,
peer: undefined,
seed: seed.host,
revision: project.head ?? undefined,
peer: undefined,
revision: undefined,
},
});
}
+1 -1
View File
@@ -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,
},