auto-register routes for default tools
This commit is contained in:
parent
f00d8be566
commit
d530cd715e
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user