Skip to content

Commit

Permalink
feat(routing): resource URL prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed May 17, 2022
1 parent 58e41c3 commit 514215d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-pumas-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hydrofoil/shell-routing": patch
---

Optional parameter to add a resource prefix
7 changes: 5 additions & 2 deletions packages/routing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import linkHijacker from '@mapbox/link-hijacker'

interface Options {
appPath?: string
pathPrefix?: string
}

interface RoutingDispatch {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 514215d

Please sign in to comment.