Use tool_name for route generation and convert underscores to hyphens

This commit is contained in:
jingrow 2025-11-21 17:40:37 +08:00
parent ea874654bd
commit c01bdf9a41

View File

@ -11,11 +11,12 @@ function generateRouteName(toolName: string): string {
} }
function generateRoutePath(toolName: string): string { function generateRoutePath(toolName: string): string {
return `tools/${toolName}` const pathName = toolName.replace(/_/g, '-')
return `tools/${pathName}`
} }
export function ensureToolRoutes(tool: Tool): Tool { export function ensureToolRoutes(tool: Tool): Tool {
const routeNameBase = tool.marketplaceId || tool.name || tool.id const routeNameBase = tool.toolName || tool.marketplaceId || tool.name || tool.id
const routePathBase = tool.toolName || tool.marketplaceId || tool.name || tool.id const routePathBase = tool.toolName || tool.marketplaceId || tool.name || tool.id
if (!tool.routeName) { if (!tool.routeName) {
@ -52,7 +53,10 @@ export function registerToolRoute(
const toolDirName = toolWithRoutes.toolName || toolWithRoutes.id const toolDirName = toolWithRoutes.toolName || toolWithRoutes.id
finalComponentPath = `../../views/tools/${toolDirName}/${toolDirName}.vue` finalComponentPath = `../../views/tools/${toolDirName}/${toolDirName}.vue`
} }
const routePath = toolWithRoutes.routePath || `tools/${toolWithRoutes.toolName || toolWithRoutes.id}` const routePath = toolWithRoutes.routePath || (() => {
const toolDirName = toolWithRoutes.toolName || toolWithRoutes.id
return `tools/${toolDirName.replace(/_/g, '-')}`
})()
const route: RouteRecordRaw = { const route: RouteRecordRaw = {
path: routePath, path: routePath,