diff --git a/.changeset/tidy-pumas-grab.md b/.changeset/tidy-pumas-grab.md new file mode 100644 index 0000000..ed14651 --- /dev/null +++ b/.changeset/tidy-pumas-grab.md @@ -0,0 +1,5 @@ +--- +"@hydrofoil/shell-routing": patch +--- + +Optional parameter to add a resource prefix diff --git a/packages/routing/index.ts b/packages/routing/index.ts index fa37b32..0a46d70 100644 --- a/packages/routing/index.ts +++ b/packages/routing/index.ts @@ -3,6 +3,7 @@ import linkHijacker from '@mapbox/link-hijacker' interface Options { appPath?: string + pathPrefix?: string } interface RoutingDispatch { @@ -15,7 +16,7 @@ const reducers = { }, } -export const routing = ({ appPath = '/' }: Options = {}) => { +export const routing = ({ appPath = '/', pathPrefix = '' }: Options = {}) => { const appPathPattern = new RegExp(`^${appPath}`) const getResourcePath = (href: string) => { @@ -49,7 +50,9 @@ export const routing = ({ appPath = '/' }: Options = {}) => { function urlChanged() { const resource = new URL(url.href) - resource.pathname = resource.pathname.replace(appPathPattern, '') + resource.pathname = resource.pathname + .replace(appPathPattern, pathPrefix) + .replace(/\/$/, '') dispatch.resource(resource.href) }