Skip to content

Commit

Permalink
Add dynamic param
Browse files Browse the repository at this point in the history
  • Loading branch information
rayc2045 committed Apr 30, 2024
1 parent 3c4492a commit 839b456
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ const router = {
}) || this.routes.find(route => route.path === '/404')
);
},
get currentRouteParam() {
if (!this.currentRoute.path.includes('/:')) return null;
const param = {};
const routePathFrags = this.currentRoute.path.split('/'),
currentPathFrags = this.currentPath.split('/');
for (let i = 0; i < routePathFrags.length; i++)
if (routePathFrags[i] !== currentPathFrags[i])
param[routePathFrags[i].split(':')[1]] = currentPathFrags[i];
return param;
},
async init() {
const loadTemplate = async route => {
route.template = await utils.getData(`./src/pages${route.component}`, 'text');
Expand Down

0 comments on commit 839b456

Please sign in to comment.