Get dynamic links and paths
This library has helpers for creating dynamic route links and route paths, without hard coding
Preparing - generate your routes config
;;// absoluteRoutes {// companies: {// path: "/companies",// component: () => {…},// },// company: {// parent: "companies",// path: "/companies/:companyId",// component: () => {…},// defaultValue: '$defaultValue',// },// filters: {// parent: 'company',// path: '/companies/:companyId/filters/:filterId',// component: () => {...},// defaultValue: '0',// }//}
getLink - for getting route link
;// result /companies/1 ;// result /companies/$defaultValue ;// result /companies/$defaultValue/filters/0 // You can pass the window.location to gathering missing paramswindow.location = 'http://localhost:3001/companies/1/filters/2';// result /companies/1/filters/2 // And override params;// result /companies/1/filters/33
getRouteParams - for getting route params from location
window.location = 'http://localhost:3001/companies/0'// paramsFromCurrentLocation {// route: {// parent: "companies",// path: "/companies/:companyId",// component: () => {…},// defaultValue: '$defaultValue',// },// match: {// path: "/companies/:companyId",// url: "/companies/0",// isExact: true,// params: {companyId: "0"},// }// }
Example