route-util.js 565 B

123456789101112131415161718192021
  1. import { toUpperFirstCase } from './util'
  2. export const getRouteName = (baseName, routeName) => {
  3. return baseName ? `${baseName}${toUpperFirstCase(routeName)}` : routeName
  4. }
  5. export const prependRoutes = (routes, { path, name } = {}) => {
  6. return routes.map(route => {
  7. if (path && route.path) {
  8. if (route.path[0] === '/') {
  9. route.path = `${path}${route.path}`
  10. } else {
  11. route.path = `${path}/${route.path}`
  12. }
  13. }
  14. if (name && route.name) {
  15. route.name = getRouteName(name, route.name)
  16. }
  17. return route
  18. })
  19. }