Enhancement
See original GitHub issueI’m submitting a…
[X] Feature request
Current behavior
Seems there is no hook for page reload or refresh. A hook like onPageRefresh() will be helpful for page refreshes.
Expected behavior
When a refresh page is initiated by user in the browser,the parent app component is reloaded. When the parent component is reloaded,there could be manual redirections on the parent component which loses the current page that the user was on. For instance,let’s say in my home component,I check to see the presence of an unexpired jwt key and redirect a user to a “home” route. Now when a user is on a “purchase” route and refreshes the page,the app home component is recreated and it redirects to the home route upon seeing the presence of an unexpired jwt key instead of reloading the “purchase” route or component.
Minimal reproduction of the problem with instructions
import {BrowserModule} from '@angular/platform-browser';
import {Component, NgModule} from '@angular/core';
import {Router, RouterModule} from '@angular/router';
@Component({
selector: 'app-root',
template: `
<router-outlet></router-outlet>
`,
styleUrls: ['./app.component.css']
})
export class MainComponent {
constructor(private router: Router) {
this.router.navigate([('home')]);
}
}
@Component({
selector: 'app-root-home',
template: `
<div>home works</div>
Go to random
`
})
export class HomeComponent {
}
@Component({
selector: 'app-root-random',
template: `
<div>random route works</div>
`
})
export class RandomComponent {
// when random component is loaded and we refresh the page,
// it riderects back to home component(ie '/home' route) instead of the same '/random' route.
}
@NgModule({
declarations: [
MainComponent,
HomeComponent,
RandomComponent
],
imports: [
BrowserModule,
RouterModule.forRoot([
{
path: '',
component: MainComponent,
children: [
{
path: 'home',
component: HomeComponent
},
{
path: 'random',
component: RandomComponent
}
]
}
])
],
providers: [],
bootstrap: [MainComponent]
})
export class AppModule {
}
What is the motivation / use case for changing the behavior?
refresh an angular page and still stay on the same page after refresh
Environment
Angular version: 5.2.0
Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: XX
- Platform:
Others:
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (7 by maintainers)
How would you like to implement that? By comparing current time and last close time? By session expiry cookie? How do you make sure there is no false positive?
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.