Skip to content
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

Remove some outdated route method references #1822

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions guides/release/models/creating-updating-and-deleting-records.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,18 @@ a promise, which makes it easy to asynchronously handle success and failure
scenarios. Here's a common pattern:

```javascript
let post = store.createRecord('post', {
// Assumed to have already injected the router and store services
const newPost = this.store.createRecord('post', {
title: 'Rails is Omakase',
body: 'Lorem ipsum'
});

let self = this;

function transitionToPost(post) {
self.transitionToRoute('posts.show', post);
}

function failure(reason) {
// handle the error
try {
await newPost.save();
this.router.transitionTo('posts.show', newPost.id);
} catch (error) {
// Handle error
}

post
.save()
.then(transitionToPost)
.catch(failure);

// => POST to '/posts'
// => transitioning to posts.show route
```

## Deleting Records
Expand Down
8 changes: 3 additions & 5 deletions guides/release/routing/redirection.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ Usually you want to redirect them to the login page, and after they have success
There are many other reasons you probably want to have the last word on whether a user can or cannot access a certain page.
Ember allows you to control that access with a combination of hooks and methods in your route.

One of the methods is [`transitionTo()`](https://api.emberjs.com/ember/release/classes/Route/methods/transitionTo?anchor=transitionTo).
Calling `transitionTo()` from a route or
[`transitionToRoute()`](https://api.emberjs.com/ember/release/classes/Controller/methods/transitionToRoute?anchor=transitionToRoute) from a controller will stop any transitions currently in progress and start a new one, functioning as a redirect.
`transitionTo()` behaves exactly like the [`LinkTo`](../../templates/links/) helper.
One of the methods is [`transitionTo()`](https://api.emberjs.com/ember/release/classes/RouterService/methods/transitionTo?anchor=transitionTo).
Calling `transitionTo()` on the router service will stop any transitions currently in progress and start a new one, functioning as a redirect.

The other one is [`replaceWith()`](https://api.emberjs.com/ember/release/classes/Route/methods/replaceWith?anchor=replaceWith) which works the same way as `transitionTo()`.
The other one is [`replaceWith()`](https://api.emberjs.com/ember/release/classes/RouterService/methods/replaceWith?anchor=replaceWith) which works the same way as `transitionTo()`.
Comment on lines +10 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be able to update the surrounding paragraphs so that the sentences flow better. To limit the scope of the work, I'd suggest that we keep the changes as is.

The only difference between them is how they manage history.
`replaceWith()` substitutes the current route entry and replaces it with that of the route we are redirecting to,
while `transitionTo()` leaves the entry for the current route and creates a new one for the redirection.
Expand Down