Skip to content

Commit

Permalink
feat(projects): add props: true if route has params
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Nov 6, 2023
1 parent 02c2382 commit f535d8b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 0 additions & 1 deletion examples/template-vue/src/router/elegant/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export const generatedRoutes: GeneratedRoute[] = [
name: 'user',
path: '/user/:id',
component: 'layout.base$view.user',
props: true,
meta: {
title: 'user'
}
Expand Down
12 changes: 10 additions & 2 deletions examples/template-vue/src/router/elegant/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ function transformElegantRouteToVueRoute(

const vueRoutes: RouteRecordRaw[] = [];

// add props: true to route
if (route.path.includes(':') && !route.props) {
route.props = true;
}

const { name, path, component, children, ...rest } = route;

const vueRoute = { name, path, ...rest } as RouteRecordRaw;
Expand Down Expand Up @@ -132,6 +137,9 @@ function transformElegantRouteToVueRoute(
return vueRoutes;
}

/**
* map of route name and route path
*/
const routeMap: RouteMap = {
"root": "/",
"not-found": "/:pathMatch(.*)*",
Expand All @@ -155,8 +163,8 @@ const routeMap: RouteMap = {
* get route path by route name
* @param name route name
*/
export function getRoutePath(name: RouteKey) {
return routeMap[name] || null;
export function getRoutePath<T extends RouteKey>(name: T) {
return routeMap[name];
}

/**
Expand Down
9 changes: 7 additions & 2 deletions packages/vue/src/core/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ function transformElegantRouteToVueRoute(
const vueRoutes: RouteRecordRaw[] = [];
// add props: true to route
if (route.path.includes(':') && !route.props) {
route.props = true;
}
const { name, path, component, children, ...rest } = route;
const vueRoute = { name, path, ...rest } as RouteRecordRaw;
Expand Down Expand Up @@ -169,8 +174,8 @@ const routeMap: RouteMap = {
* get route path by route name
* @param name route name
*/
export function getRoutePath(name: RouteKey) {
return routeMap[name] || null;
export function getRoutePath<T extends RouteKey>(name: T) {
return routeMap[name];
}
/**
Expand Down

0 comments on commit f535d8b

Please sign in to comment.