feat(router) added method to convert an Url to RouterStateSnapshot#15826
feat(router) added method to convert an Url to RouterStateSnapshot#15826smurfy wants to merge 1 commit intoangular:masterfrom
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
I signed it! |
|
CLAs look good, thanks! |
268b80d to
7d1eb7d
Compare
|
What is the status of this? When can we expect this feature to be released? |
|
what's the status of this? any advances? I really need something like this |
jasonaden
left a comment
There was a problem hiding this comment.
Thanks for the PR and sorry for the delay. This looks very useful.
One change requested, and please add a test for this method.
packages/router/src/router.ts
Outdated
There was a problem hiding this comment.
Our Observables do not have the Rxjs prototype methods. So you would need to import toPromise in order to return a promise here. So:
import {toPromise} from 'rxjs/operator/toPromise';
...
return toPromise.call(snapshot$);
|
@smurfy Are you able to make the updates on this PR? |
|
@jasonaden I will have a look tomorrow regarding the promise thing. Regarding Unit tests i need to read-up on. We only do selenium tests and as mentioned in the initial comment, the new method is only a wrapper for "recognize" which is already unit tested quite heavily. So i'm not sure if we really need unit tests. |
|
I updated my PR with your suggested changes and added an unit-test. |
c8d2d13 to
6ea35fa
Compare
|
@jasonaden Updated the code to be conflict free to master, also fixed tslint errors, which was quite stupid, because somehow a local tslint does not show the errors. |
|
Any updates here? I'd love to see this PR land |
|
I took another look at this PR and have some different thoughts on it. Right now you're doing I can't think of a use case where we actually want this method to be async. If you can think of one, let me know. Otherwise we should convert this to be sync instead. |
|
@jasonaden well i think async makes sense, because it is possible, that not all routes are available yet. due to async modules. Other than that, the main logic needed is in the |
|
@jasonaden how you are using applyRedirects |
|
Please note that this wouldn't work for Lazy Loaded modules... |
well it does not trigger the loading of all modules to get all routes, but if the module is already loaded it works. |
|
Any news on this? |
|
Ping. This would be very useful indeed. |
|
@smurfy - This would be very useful indeed and is exactly what I'm looking for. Can you update this to the latest version of angular? Thanks! |
|
I really need this two... |
|
Hey @jasonaden , I'm doing this as soon as I have your answer. |
|
We're trying to clean up the oldest PRs now, and this is the oldest Router PR (sorry for all the delays). Overall it looks good. There have been a number of changes to Other than that, I believe this is good to go. |
|
Ok, try to rebase it today |
|
@smurfy Let me know if you need help on the rebase here. I'm sometimes on Gitter, or you can DM me on Twitter at jasonaden1 |
| ]); | ||
|
|
||
| r.urlToRouteStateSnapshot('/a').then( | ||
| (s) => { expect(s.root.firstChild !.data).toEqual({state: 'i am A'}); }); |
There was a problem hiding this comment.
Hmm, do these asynchronous expectations actually work reliably? I think nowadays we should use async/await instead, as doing so will return a Promise to jasmine which it will wait for.
There was a problem hiding this comment.
No they don't, tested it
|
Any news on this please? |
|
@jasonaden since you declined the merge how can I help to fix this please so you accept it. I really need this feature. Thanks. |
atscott
left a comment
There was a problem hiding this comment.
Please also address the comments in #15826 (comment)
| recognize(this.rootComponentType, this.config, appliedUrl, this.serializeUrl(appliedUrl)), | ||
| (snapshot: any) => { return snapshot; }); | ||
| }); | ||
| return toPromise.call(snapshot$); |
There was a problem hiding this comment.
Why not just leave it as an Observable and let the caller decide if they want to use toPromise or not?
| path: 'a', | ||
| component: ComponentA, | ||
| data: {state: 'i am A'}, | ||
| children: [{path: 'b', component: ComponentB, data: {state: 'i am B'}}] |
There was a problem hiding this comment.
Let's also add a test for lazy loaded modules. Even if it doesn't work (though I don't immediately see why it wouldn't), the test documents the behavior. It does seem to me like this would actually trigger the lazy loading. If that's true, this needs to be documented.
|
Closing due to lack of activity. If you're still interested in working on this change, please open a new PR (and address the feedback from this one) and I'll be happy to review it. Thanks! |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x")
What is the current behavior? (You can also link to an open issue here)
There is no clean way to convert an url to a route.
See #15750
What is the new behavior?
You now can convert any url to a routestatesnapshot (if they exist).
This is will allows you to easily generate breadcrumbs or create a directive to check access to a routeLink
Does this PR introduce a breaking change? (check one with "x")
Other information:
I did not include any tests because of the size of the change and the actual logic is in the recognize function which is already has its own tests.