UNPKG

@refinedev/core

Version:

Refine is a React meta-framework for building enterprise-level, data-intensive applications rapidly with support for modern UI libraries and headless integrations.

33 lines (28 loc) 934 B
import type { Action } from "../../../contexts/router/types"; import { removeLeadingTrailingSlashes } from "./remove-leading-trailing-slashes"; /** * This helper function returns the default path for a given action and resource. * It also applies the parentPrefix if provided. */ export const getDefaultActionPath = ( resourceName: string, action: Action, parentPrefix?: string, ): string => { const cleanParentPrefix = removeLeadingTrailingSlashes(parentPrefix || ""); let path = `${cleanParentPrefix}${ cleanParentPrefix ? "/" : "" }${resourceName}`; if (action === "list") { path = `${path}`; } else if (action === "create") { path = `${path}/create`; } else if (action === "edit") { path = `${path}/edit/:id`; } else if (action === "show") { path = `${path}/show/:id`; } else if (action === "clone") { path = `${path}/clone/:id`; } return `/${path.replace(/^\//, "")}`; };