-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX release] Add model hook in route blueprint
When generating a route with a dynamic segment, say via: ember g route foo --path="bar/:buzz_id" The default empty route definition will cause an awkward assertion to be thrown. * In 3.28 without any data layer, the user is prompted via assertion to implement a model hook. * In 3.28 with Ember Data, an implicit fetch via Ember Data happens. * In 4.0 without any data layer, the user would be prompted via assertion to implement a model hook. * In 4.0 with Ember Data, the user would be prompted via assertion to either add a `find` method (old assertion) or to implement a model hook (new assertion via #19858). It is doubtless that many users will still encounter these behaviors, but updating the blueprints to generate a model hook by default improves on the happy path. In theory this could do back to 3.28, however the value there is somewhat less since Ember Data's implicit store injection remains in that version (and therefore the assertions/messages are less confusing). (cherry picked from commit e253e92)
- Loading branch information
1 parent
5971276
commit 31af99a
Showing
6 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default Route.extend({ | ||
export default Route.extend({<% if (hasDynamicSegment) {%> | ||
model(params) { | ||
/** | ||
* This route was generated with a dynamic segment. Implement data loading | ||
* based on that dynamic segment here in the model hook. | ||
*/ | ||
return params; | ||
},<%}%> | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default class <%= classifiedModuleName %>Route extends Route { | ||
export default class <%= classifiedModuleName %>Route extends Route {<% if (hasDynamicSegment) {%> | ||
model(params) { | ||
/** | ||
* This route was generated with a dynamic segment. Implement data loading | ||
* based on that dynamic segment here in the model hook. | ||
*/ | ||
return params; | ||
}<%}%> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
node-tests/fixtures/route/native-route-with-dynamic-segment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default class FooRoute extends Route { | ||
model(params) { | ||
/** | ||
* This route was generated with a dynamic segment. Implement data loading | ||
* based on that dynamic segment here in the model hook. | ||
*/ | ||
return params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default Route.extend({ | ||
model(params) { | ||
/** | ||
* This route was generated with a dynamic segment. Implement data loading | ||
* based on that dynamic segment here in the model hook. | ||
*/ | ||
return params; | ||
}, | ||
}); |