1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-06 05:55:28 +00:00
bramw_baserow/web-frontend/modules/builder/utils/routing.js
Petr Stribny f2bc3ce901 Merge branch '1675-bump-frontend-deps' into 'develop'
Resolve "Bump frontend deps"

Closes 

See merge request 
2023-04-28 10:56:33 +00:00

23 lines
758 B
JavaScript

import { pathToRegexp } from 'path-to-regexp'
export const resolveApplicationRoute = (pages, fullPath) => {
let found
for (const page of pages) {
const keys = [] // Keys are populated by the next call
const re = pathToRegexp(page.path, keys)
const match = re.exec(fullPath)
if (match) {
// The page path has matched we can stop here our search and return the result
const [path, ...paramValues] = match
// TODO the parameter resolution here is really simple. Should be enough for a
// long time but we can do better here.
const params = Object.fromEntries(
paramValues.map((paramValue, index) => [keys[index].name, paramValue])
)
return [page, path, params]
}
}
return found
}