Repository: angular
Issue: Retrieve all route segments configuration by URL
Labels: feature,area: router,router: config matching/activation/validation,router: guards/resolvers

**Note**: This issue was recreated from the discussion as we over eagerly converted it to a discussion before we had confirmed our process for potentially using discussions for this type of issue.  I have moved it to back to an issue, and you can see the original issue with comments at https://github.com/angular/angular/issues/15750.


<div type='discussions-op-text'>

<sup>Originally posted by **smnbbrv** April  4, 2017</sup>
<!--
IF YOU DON'T FILL OUT THE FOLLOWING INFORMATION WE MIGHT CLOSE YOUR ISSUE WITHOUT INVESTIGATING
-->

**I'm submitting a ...**  (check one with "x")
```
[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
```

**Current behavior**
<!-- Describe how the bug manifests. -->
There is no clear way to get the configuration, see http://stackoverflow.com/q/43143621/1990451.

Given a URL, e.g. `/path/path2/path3/123;sdf=df` and a routes configuration:

    { path: 'path', data: { g: 'h' }, children: [
      { path: 'path2', data: { c: 'd' }, children: [
        { path: 'something', component: TestpageComponent, data: { a: 'b' } },
        { path: 'path3/create', component: TestpageComponent, data: { b: 'c' } },
        { path: 'path3/:id', component: TestpageComponent, data: { b: 'c' } },
      ] }
    ] },

It would be useful to find an actual configuration for all the segments in order to e.g. get a result set of all `data` parameters on all levels (each segment of the url).

It is possible to split the URL to the segments by e.g.

    console.log(this.router.parseUrl(url));

or to be more precise

    console.log(this.router.parseUrl(url).root.children['primary'].segments);

which will return 

    [{"path":"path","parameters":{}},{"path":"path2","parameters":{}},{"path":"and","parameters":{}},{"path":"123","parameters":{"sdf":"df"}}]

So, splitting the URL into segments is not a problem. However it does not provide the configuration for each segment. One can get the actual configuration for all the routes with

    console.log(this.router.config);

It's possible to go with the parsed segments through the configuration tree and resolve the branch (and it's not that complicated actually), but it can cause troubles e.g. while resolving `:id` against `create` segment. So, it would be cool to use the *router's* way of resolving the configuration.

**Expected behavior**
<!-- Describe what the behavior would be without the bug. -->
I would expect a method on a `Router` service that returns an array of all the configurations available for a given URL. E.g.

    router.configurationByUrl('/path/path2/path3/123;sdf=df')
    // returns [
    //  { path: 'path', data: { g: 'h' }, children: [...] },
    //  { path: 'path2', data: { c: 'd' }, children: [...] },
    //  { path: 'path3/:id', component: TestpageComponent, data: { b: 'c' } }
    //], 

**Minimal reproduction of the problem with instructions**
<!--
If the current behavior is a bug or you can illustrate your feature request better with an example, 
please provide the *STEPS TO REPRODUCE* and if possible a *MINIMAL DEMO* of the problem via
https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).
-->


**What is the motivation / use case for changing the behavior?**
<!-- Describe the motivation or the concrete use case -->
Imagine I have a 50% of the URLs protected by some guard (e.g. only logged in users could go there) and other 50% is not protected (displayed for everybody). So, on the navigation menu level (outside of the `router-outlet`) I want to display only the links which are relevant for the current user, so I need to know which routes are protected by the guard. Guards / data / whatever is just a particular case of the problem.

**Please tell us about your environment:**
<!-- Operating system, IDE, package manager, HTTP server, ... -->

* **Angular version:** 2.0.X / 4.0.X
<!-- Check whether this is still an issue in the most recent Angular version -->

* **Browser:** [all]
<!-- All browsers where this could be reproduced -->
 
* **Language:** [all]

* **Node (for AoT issues):** `node --version` =  X</div>