-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Router's ActivatedRoute data
returns empty {} if module is lazy
#19420
Comments
data
returns empty {} for lazy modulesdata
returns empty {} if module is lazy
Tried to subscribe for route changes in my
|
And this is if you have children:
|
Thanks, you just saved me |
Nothing new about it, four months later ? I have been racking my brain one week before getting into this issue. Considering there are a lot of important use cases (in my case: authentication with roles) this issue should be handled |
Try it:
|
No no, use rxjs 5.5+! Similar like this: this.router.events.pipe(
filter(event => event instanceof ChildActivationEnd),
take(1),
).subscribe... |
@artuska Can you produce a reproduction? I would like to look into this. Please add a StackBlitz with a minimal repro. |
Since no reproduction added over the last week, I'm closing this issue. If this is still a problem, please create a new issue with the reproduction included. |
Hi @jasonaden Here's my reproduction: https://stackblitz.com/edit/angular-rakecj If you click on the buttons, the data should never be |
@jasonaden |
I finally found solution this.router.events.pipe(
filter(event => event instanceof ResolveStart),
map(event => {
let data = null;
let route = event['state'].root;
while (route) {
data = route.data || data;
route = route.firstChild;
}
return data;
}),
).subscribe(console.log); |
routerに紐付いたほうが良さそうだ angular/angular#19420
one more solution
|
@romatron Thank you so much! |
@romatron Thanks for the solution. I had to modify it a bit for my case, because when the route gets opened directly from the browsers address bar, there won't be an ActivationStart event, but an ActivationEnd event, which works aswell. and i took the last segment of the route (when there are no children), because for every segment there're events fired.
|
Is it normal that I get the data in the format of:
|
For Angular 7.2.4 constructor(private route: ActivatedRoute) {}
ngOnInit() {
const currentActivatedRoute = this.route.pathFromRoot[this.route.pathFromRoot.length - 1]
currentActivatedRoute.data.subscribe((v) => console.log(v))
} |
This is still a problem. Why is this still closed and not reopened? What is the point of just creating more and more issues when we have a perfectly good one right here with a bunch of different workarounds already that shows to what length we have to go to access the information we need?! Please make this a priority. |
@yozman you saved me, thank you very much ! @CAspeling because that would require to realize the inconsistencies in angular instead of rather having the community come up with 10 workarounds. It would all be easy for everyone if the likes of
just did the job they were intended for, but instead for some reasons no one should have to care about the returned values are empty in some setups, and you need to poke around the internet, stumbling upon fixes with a half life of a few months because of the ever breaking syntax changes in lower-level functionalities. Will this ever stop ? |
Hi Guys, I've followed this: https://stackblitz.com/github/jbojcic1/angular-routing-example/tree/routing-reuse-layout-example-3-with-subscribing-to-route-events?file=src%2Fapp%2Fapp-routing.module.ts But I can get that working with angular 8.2.0 any ideas what could be happening here? |
Please if anyone is having problem with this, please check this: #31778 (comment) |
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. |
I'm submitting a...
Current behavior
A subscription on ActivatedRoute's
data
parameter outputs empty{}
if the module is lazy.Expected behavior
this.route.data.subscribe((data) => console.log(data));
must output route'sdata
object.Minimal reproduction of the problem with instructions
app.routing.ts:
app.component.html
terms.routing.ts:
And here is
top-panel
component which is inside theapp.component.html
:(As you see I put
data
in both routings just for make sure subscription will work — well, it does not work).Environment
Similar issues
#12767 have
children
array in the routing and issue is resolved withroute.parent
but I have no any child routes therefore I have no anyparent
reference.The text was updated successfully, but these errors were encountered: