Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
fix: keep the routes we are closing or replacing
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Oct 3, 2019
1 parent 19be2b4 commit bc3586a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/stack/src/views/Stack/StackView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ class StackView extends React.Component<Props, State> {
);
}

if (!routes.length) {
throw new Error(`There should always be at least one route.`);
}

// If there was no change in routes, we don't need to compute anything
if (routes === state.routes || !state.routes.length) {
return {
Expand Down Expand Up @@ -144,6 +140,20 @@ class StackView extends React.Component<Props, State> {
// i.e. the currently focused route already existed and the previously focused route still exists
// We don't know how to animate this
}
} else {
// Keep the routes we are closing or replacing
routes = routes.slice();
routes.splice(
routes.length - 1,
0,
...state.routes.filter(
({ key }) => replacing.includes(key) || closing.includes(key)
)
);
}

if (!routes.length) {
throw new Error(`There should always be at least one route.`);
}

const descriptors = routes.reduce(
Expand Down

0 comments on commit bc3586a

Please sign in to comment.