[Bug] Chained redirects triggered via `routeWillChange` lead to calling model() hook with wrong params
- Dominant language
- TypeScript
- Stars
- 22.6k
- Forks
- 4.2k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 15
Description
### 🐞 Describe the Bug
When there is a chain of two redirects triggered via a `routeWillChange` hook, the destination route model() hook is called twice, and is called with the wrong parameters.
### 🔬 Minimal Reproduction
```js
// Route config:
this.route('dynamic', { path: '/dynamic/:dynamic_id' });
```
```js
// RouteWillChange hook:
routerService.on('routeWillChange', (transition) => {
let to = transition.to;
if (to.name === 'dynamic') {
if (to.params.dynamic_id === '1') {
this.routerService.transitionTo('dynamic', '2');
} else if (to.params.dynamic_id === '2') {
this.routerService.transitionTo('dynamic', '3');
}
}
});
```
Visiting `/dynamic/1` will redirect to `/dynamic/3`, but the model hook will be called (twice) with `dynamic_id=2`.
Failing test case in https://github.com/emberjs/ember.js/pull/20612
### 😕 Actual Behavior
The model hook will be called (twice) with `dynamic_id=2`.
### 🤔 Expected Behavior
The model hook should be called once with `dynamic_id=3`
### 🌍 Environment
Tested under Ember 3.28 and 5.6.0.beta2
Contributor guide
Assessment
This issue has not been assessed yet.