T
TanStack11mo ago
unwilling-turquoise

Replace history for entire sub path

There's a portion of our application that we don't want to put into browser history. /dashboard/editor/** Is there anyway to disable it at the route level so that we don't have to call replace:true on every navigate/Link?
3 Replies
extended-salmon
extended-salmon11mo ago
a custom function to do this? even if there was a way to do this, i wont since it would seem too "magical" because when you eventually do forget that you configured this, you will end up spending hours trying to debug why a particular route is not being added to history
unwilling-turquoise
unwilling-turquoiseOP11mo ago
It's an entire subsection of an application it's not just one route.
adverse-sapphire
adverse-sapphire11mo ago
you could solve this at the history level but there you only get the full href, not a route
const history = createBrowserHistory()
const originalPush = history.push
history.push = (path: string, state?: any, navigateOpts?: NavigateOptions) => {
if (path.startsWith('/dashboard/editor/')) {
history.replace(path, state, navigateOpts)
}
else {
originalPush(path, state, navigateOpts)
}
}

const router = createRouter({
routeTree,
history,
})
const history = createBrowserHistory()
const originalPush = history.push
history.push = (path: string, state?: any, navigateOpts?: NavigateOptions) => {
if (path.startsWith('/dashboard/editor/')) {
history.replace(path, state, navigateOpts)
}
else {
originalPush(path, state, navigateOpts)
}
}

const router = createRouter({
routeTree,
history,
})
did this work as you want it?

Did you find this page helpful?