-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better state management for Rockd StraboSpot
- Loading branch information
1 parent
065f5ba
commit 4847b68
Showing
6 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { partRegex } from "part-regex"; | ||
import { redirect } from "vike/abort"; | ||
|
||
const prefix = "/dev/map/rockd-strabospot"; | ||
|
||
const lngLatRegex = /(-?\d+\.\d+)/; | ||
|
||
const routeRegex = partRegex`/loc/${lngLatRegex}/${lngLatRegex}`; | ||
|
||
export function route(pageContext) { | ||
const url = pageContext.urlPathname; | ||
|
||
if (!url.startsWith(prefix)) return false; | ||
|
||
const suffix = url.slice(prefix.length); | ||
|
||
if (suffix == "" || suffix == "/") { | ||
return { | ||
routeParams: {}, | ||
}; | ||
} | ||
|
||
if (suffix.match(routeRegex)) { | ||
const [_, lng, lat] = suffix.match(routeRegex); | ||
return { | ||
routeParams: { | ||
lng, | ||
lat, | ||
}, | ||
}; | ||
} | ||
|
||
// Redirect to the root of this route | ||
throw redirect(prefix); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters