格式化形如 /data/{id}/abc/{path}的url,结果返回类似/data/1/abc/123

const formatUrl = (url: string, path: object) => {
const reg = new RegExp(/\{(\w+)\}/, "g");
return url.replace(reg, ($0: any, $1: any) => {
return path[$1];
});
};

posted @ 2019-05-27 16:40  炫冰G爱  阅读(220)  评论(0编辑  收藏  举报