Skip to content

Commit

Permalink
fix: strip trailing /index from urls
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Aug 19, 2023
1 parent a64844f commit 7dde649
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/runtime/Router/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
createSequenceHooksCollection,
} from 'hookar'
import reset from '../plugins/reset/index.js'
import stripTrailingIndex from '../plugins/stripTrailingIndex'
import scroller from '../plugins/scroller/plugin.js'

import { next } from '../../common/utils.js'
Expand All @@ -36,7 +37,7 @@ import { URIDecodeObject } from '../Route/utils.js'
const stripNullFields = obj =>
Object.fromEntries(Object.entries(obj).filter(([_, v]) => v != null))

const defaultPlugins = [reset(), scroller()]
const defaultPlugins = [reset(), scroller(), stripTrailingIndex()]

/**
* @implements { Readable<Router> }
Expand Down
12 changes: 12 additions & 0 deletions lib/runtime/plugins/stripTrailingIndex/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Strips trailing /index from a url
* @returns {RoutifyRuntimePlugin}
**/
export default () => ({
urlRewrite: [
{
toExternal: url => url.replace(/\/index(?=$|\?|#)/, ''),
toInternal: url => url,
},
],
})

0 comments on commit 7dde649

Please sign in to comment.