Skip to content

Commit

Permalink
Fix empty prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
JAForbes committed Feb 15, 2024
1 parent 204fdec commit 062ac5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/index.ts
Expand Up @@ -32,11 +32,14 @@ interface ChildAttrs {
function normalizePath(str: string): string {
if (str == '' || str == '/') {
return '/'
} else if (str.at(-1) == '/') {
return str.slice(0, -1)
} else {
return str
}
if (str.at(-1) == '/') {
str = str.slice(0, -1)
}
if ( str[0] != '/' ) {
str = '/' + str
}
return str
}

function Superhistory({
Expand Down
10 changes: 10 additions & 0 deletions test/index.ts
Expand Up @@ -51,3 +51,13 @@ test('Basics', () => {

assert.deepEqual(C1.get(), { path: '/' })
})

test('Child with empty prefix', () => {

const {superhistory} = setup()

superhistory.go('/financials/edit/1')
const A = superhistory.child({ prefix: ''})

assert.equal('/financials', A.get().path)
})

0 comments on commit 062ac5a

Please sign in to comment.