I try to split URLs into segments. These segments got two information, their name and their own URL.

The last segment in the segments list should not have the URL property because it's the current URL from the browser. There is no need for it.

I created this code which works really fine

```js
const directoryPath = 'rootFolder/folder1/exampleFolder1/folder3/folder3/subFolder123/file2.md';

const segments = directoryPath.split('/');

const info = segments.map((segment, index) => {

  const item = {
    name: segment
  };

  if (index < segments.length - 1) {
    let route = '';

    for (let i = 0; i <= index; i++) {
      route += `/${segments[i]}`;
    }

    item.url = route;
  }

  return item;
});

console.log(info);
```

I don't know if this is the only way doing this, maybe there is a more optimized way. I don't know if I really need the for-loop because at the top of the code I split the URL into segments and after that I create smaller URLs out of it.

Is there a better / easier way?