Typescript replace route params

Date: 2022-05-23
export function replaceAppRoutesParams(route: RoutingNames, ...params: string[]) {
    var path = String(route);
    let i = 0;
    const getParam = () => {
        const param = params[i];
        i += 1;
        return encodeURIComponent(param);
    };
    return path.replace(/(:[^/]+)/g, getParam);
}

export function navigateToWithParams(route: RoutingNames, ...params: string[]) {
    navigateTo(replaceAppRoutesParams(route, ...params));
}
// Get params in Angular Routing
export class MyComponent {
    returnUrl?: string;

    constructor(private _route: ActivatedRoute) {
        super();
    }

    ngOnInit(): void {
        this._route.paramMap.subscribe(async (event: any) => {
            this.returnUrl = decodeURIComponent(event.params.returnurl);
        });
    }
}
62060cookie-checkTypescript replace route params