feat: allow deep linking to reset state (#8973)

Currently when we receive a deep link after the app is rendered, it always results in a `navigate` action. While it's ok with the default configuration, it may result in incorrect behaviour when a custom `getStateForPath` function is provided and it returns a routes array different than the initial route and new route pair.

The commit changes 2 things:

1. Add ability to reset state via params of `navigate` by specifying a `state` property instead of `screen`
2. Update `getStateForAction` to return an action for reset when necessary according to the deep linking configuration

Closes #8952
This commit is contained in:
Satyajit Sahoo
2020-10-24 15:27:06 +02:00
committed by GitHub
parent f51086edea
commit 7f3b27a9ec
9 changed files with 737 additions and 88 deletions

View File

@@ -50,16 +50,18 @@ export type InitialState = Readonly<
}
>;
export type PartialRoute<R extends Route<string>> = Omit<R, 'key'> & {
key?: string;
state?: PartialState<NavigationState>;
};
export type PartialState<State extends NavigationState> = Partial<
Omit<State, 'stale' | 'type' | 'key' | 'routes' | 'routeNames'>
> &
Readonly<{
stale?: true;
type?: string;
routes: (Omit<Route<string>, 'key'> & {
key?: string;
state?: InitialState;
})[];
routes: PartialRoute<Route<string>>[];
}>;
export type Route<