I'm trying to create Breadcrumbs navigation and I'm stuck while creating parent URLs.
So my idea is:
get a full URL from child level
splitting that URL with slashes and recombining them sequentially
So simply if the URL is:
www.nice.com/events/registration/form
then, split to like:
www.nice.com/events/registration/form
www.nice.com/events/registration
www.nice.com/events
www.nice.com
and reverse the order and push into array like:
['www.nice.com', 'www.nice.com/events', 'www.nice.com/events/registration', 'www.nice.com/events/registration/form']
You can split the URL's
pathnameon the URL path separator character/and then iterate the path parts to build your list:TS Playground
Compiled JS from the playground: