auto-register routes for default tools

This commit is contained in:
jingrow 2025-11-21 22:36:01 +08:00
parent f00d8be566
commit d530cd715e
3 changed files with 8 additions and 9 deletions

View File

@ -90,11 +90,6 @@ const router = createRouter({
name: 'Tools',
component: () => import('../../views/Tools.vue')
},
{
path: 'tools/remove-background',
name: 'RemoveBackground',
component: () => import('../../views/tools/remove_background/remove_background.vue')
},
{
path: 'search',
name: 'SearchResults',
@ -203,7 +198,7 @@ router.beforeEach(async (to, _from, next) => {
await authStore.initAuth()
}
if (to.path.startsWith('/tools/') && to.name !== 'Tools' && to.name !== 'RemoveBackground') {
if (to.path.startsWith('/tools/') && to.name !== 'Tools') {
const routeExists = to.matched.length > 0 || router.getRoutes().some(r => {
const fullPath = r.path.startsWith('/') ? r.path : `/${r.path}`
return fullPath === to.path

View File

@ -220,7 +220,12 @@ export const useToolsStore = defineStore('tools', () => {
}
function initToolRoutes(router: Router) {
registerAllToolRoutes(router, userTools.value)
const defaultTools = getDefaultTools()
.filter(tool => !deletedDefaultToolIds.value.includes(tool.id))
.map(tool => ({ ...tool, isDefault: true }))
const allToolsToRegister = [...defaultTools, ...userTools.value]
registerAllToolRoutes(router, allToolsToRegister)
}
return {

View File

@ -107,8 +107,7 @@ export function unregisterToolRoute(router: Router, routeName: string): boolean
}
export function registerAllToolRoutes(router: Router, tools: Tool[]): void {
const routeTools = tools.filter(t => !t.isDefault)
routeTools.forEach(tool => {
tools.forEach(tool => {
registerToolRoute(router, tool, tool.componentPath)
})
}