ngOnInit not firing when clicking browser's back button.
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:
Current behavior
I’m having problems with routes that involve parameters. When I try to go back with the browser’s back button from a route with a parameter like person/:id the ngOnInit of the previous component doesn’t fire. This only happens when deploying the app to production.
Expected behavior
The ngOnInit of the previous component should be called and render the component correctly.
Minimal reproduction of the problem with instructions
Steps to reproduce the error with the angular’s tutorial:
- Download the tutorial from Angular’s tutorial and run npm install
- Build the app with the command
ng build --prod --build-optimizerorng build --prod - Upload the static files generated by the previous step to an nginx or apache server with the respective configuration file having the recomended lines of code in angular docs. Angular Deployment
- Click one of the top heros in the dashboard.
- Click browser’s back button.
By following those steps you will see the top heros are not loaded in the dashboard which is exactly the same problem I’m having with my app. This is be cause ngOnInit is not called when going back specifically with the back button.
Environment
Angular version: 6.0.0 and 7.0.1
Browser:
- [x] Chrome (desktop) version 69.0
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [x] Firefox version 63.0
- [x] Safari (desktop) version 12
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: 10.5.0
- Platform: Mac, Linux, Windows
Others:
This problem doesn't accurs while using development mode ng serve and trying the app locally.
It only happens when deploying to a subdomain like "subdomain.domain.com" but works perfectly in a normal domain "domain.com". I'm not sure if this could be considered a normal behavior.Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:35 (5 by maintainers)
Top Results From Across the Web
Angular 6 ngOnInit not firing when clicking browser's back button
I'm having problems with routes that involve parameters. When I try to go back with the browser's back button the ngoninit of the...
Read more >IONIC 4 -> Back Button - ngonInit or ionViewWillEnter never fired
Hi, i had a Ionic 4 App with Tabs Navigation and Angular and when i open a subpage from my Tab1 Page and...
Read more >take user to home on clicking browser back button-angular.js
In this case pressing back will move the user to the Home page. ... Angular 6 ngOnInit not firing when clicking browser's back...
Read more >OnInit - Angular
A lifecycle hook that is called after Angular has initialized all data-bound ... Define an ngOnInit() method to handle any additional initialization tasks....
Read more >Browser Back Button doesn't reload route : r/angular - Reddit
Sometimes when clicking the browser back button, the previous page is ... does run its ngOnInit, but the page component does not get...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the issue here, but it sounds more like a support request that should be sent over to StackOverflow. If you feel there’s a specific error, please make a reproduction that can be quickly and easily run.
That being said, it sounds like you might just be re-using components when hitting back.
I am facing same issue with angular 7 i.e. ngOnInit event is not firing when clicking browser’s back for forward button. @jasonaden Can you please provide solution or work around for this?