Is there a better way to get the path name of a URI without any resource ids? [closed]

1 week ago 10
ARTICLE AD BOX

Most other questions I have found about this topic entail having GET parameters à la base-url.com/route?param=value. However, my application uses routes similar to

base-url.com/resources/1 base-url.com/resources/edit/1

and I want to extract the entire path name of the URL/URI except for any resource IDs at the end (/resources and /resources/edit respectively).

I've tried doing something like

let path = /^\D+/.exec(window.location.pathname)[0]; // string until first number path = path.replace(/\/+$/, ''); // removes the slash at the end

to get everything until the first digit (because the IDs in my use cases are digits). Does anyone know of a more secure/foolproof way of doing this?

Read Entire Article