export const routerHistory = createWebHistory()
export const router = createRouter({
history: routerHistory,
+ pathOptions: { strict: true },
routes: [
{ path: '/home', redirect: '/' },
{
const delay = (t: number) => new Promise(resolve => setTimeout(resolve, t))
+// remove trailing slashes
+router.beforeEach((to, from, next) => {
+ if (/.\/$/.test(to.path)) {
+ to.meta.redirectCode = 301
+ next(to.path.replace(/\/$/, ''))
+ } else next()
+ // next()
+})
+
router.beforeEach(async (to, from, next) => {
// console.log(`Guard from ${from.fullPath} to ${to.fullPath}`)
if (to.params.id === 'no-name') return next(false)
computeScrollPosition,
scrollToPosition,
} from './scrollBehavior'
-import { createRouterMatcher } from './matcher'
+import { createRouterMatcher, PathParserOptions } from './matcher'
import {
createRouterError,
ErrorTypes,
* {@link RouterOptions.parseQuery | `parseQuery`} counterpart to handle query parsing.
*/
stringifyQuery?: typeof originalStringifyQuery
- // TODO: allow customizing encoding functions
+
+ /**
+ * Global matcher rules applied to every route record.
+ */
+ pathOptions?: PathParserOptions
}
export interface Router {
scrollBehavior,
parseQuery = originalParseQuery,
stringifyQuery = originalStringifyQuery,
+ pathOptions = {},
}: RouterOptions): Router {
- const matcher = createRouterMatcher(routes, {})
+ const matcher = createRouterMatcher(routes, pathOptions)
const beforeGuards = useCallbacks<NavigationGuardWithThis<undefined>>()
const beforeResolveGuards = useCallbacks<NavigationGuardWithThis<undefined>>()