mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 22:39:41 +08:00
fix: default to backBehavior: firstRoute for TabRouter
BREAKING CHANGE: Returning to first route after pressing back seems more common in apps. This commit changes the default for tab and drawer navigators to follow this common practice. To preserve previous behavior, you can pass backBehavior=history to tab and drawer navigators.
This commit is contained in:
@@ -147,5 +147,7 @@ it('integrates with the history API', () => {
|
||||
|
||||
act(() => navigation.current?.navigate('Home'));
|
||||
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(window.location.pathname).toBe('/edit');
|
||||
});
|
||||
|
||||
@@ -140,7 +140,7 @@ const changeIndex = (
|
||||
|
||||
export default function TabRouter({
|
||||
initialRouteName,
|
||||
backBehavior = 'history',
|
||||
backBehavior = 'firstRoute',
|
||||
}: TabRouterOptions) {
|
||||
const router: Router<
|
||||
TabNavigationState<ParamListBase>,
|
||||
|
||||
@@ -28,7 +28,10 @@ it('gets initial state from route names and params with initialRouteName', () =>
|
||||
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||
],
|
||||
history: [{ type: 'route', key: 'baz-test' }],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar-test' },
|
||||
{ type: 'route', key: 'baz-test' },
|
||||
],
|
||||
stale: false,
|
||||
type: 'drawer',
|
||||
});
|
||||
@@ -111,7 +114,10 @@ it('gets rehydrated state from partial state', () => {
|
||||
{ key: 'baz-0', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||
],
|
||||
history: [{ type: 'route', key: 'baz-0' }],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar-test' },
|
||||
{ type: 'route', key: 'baz-0' },
|
||||
],
|
||||
stale: false,
|
||||
type: 'drawer',
|
||||
});
|
||||
@@ -137,7 +143,10 @@ it('gets rehydrated state from partial state', () => {
|
||||
{ key: 'baz-1', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
|
||||
],
|
||||
history: [{ type: 'route', key: 'qux-2' }],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar-0' },
|
||||
{ type: 'route', key: 'qux-2' },
|
||||
],
|
||||
stale: false,
|
||||
type: 'drawer',
|
||||
});
|
||||
@@ -187,11 +196,7 @@ it('gets rehydrated state from partial state', () => {
|
||||
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||
],
|
||||
history: [
|
||||
{ type: 'route', key: 'qux-test' },
|
||||
{ type: 'route', key: 'bar-test' },
|
||||
{ type: 'drawer' },
|
||||
],
|
||||
history: [{ type: 'route', key: 'bar-test' }, { type: 'drawer' }],
|
||||
stale: false,
|
||||
type: 'drawer',
|
||||
});
|
||||
@@ -256,10 +261,7 @@ it('handles navigate action', () => {
|
||||
{ key: 'baz', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'bar', name: 'bar' },
|
||||
],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar' },
|
||||
{ type: 'route', key: 'baz' },
|
||||
],
|
||||
history: [{ type: 'route', key: 'baz' }],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -297,10 +299,7 @@ it('handles navigate action with open drawer', () => {
|
||||
{ key: 'baz', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'bar', name: 'bar' },
|
||||
],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar' },
|
||||
{ type: 'route', key: 'baz' },
|
||||
],
|
||||
history: [{ type: 'route', key: 'baz' }],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ it('gets initial state from route names and params with initialRouteName', () =>
|
||||
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||
],
|
||||
history: [{ type: 'route', key: 'baz-test' }],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar-test' },
|
||||
{ type: 'route', key: 'baz-test' },
|
||||
],
|
||||
stale: false,
|
||||
type: 'tab',
|
||||
});
|
||||
@@ -111,7 +114,10 @@ it('gets rehydrated state from partial state', () => {
|
||||
{ key: 'baz-0', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||
],
|
||||
history: [{ type: 'route', key: 'baz-0' }],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar-test' },
|
||||
{ type: 'route', key: 'baz-0' },
|
||||
],
|
||||
stale: false,
|
||||
type: 'tab',
|
||||
});
|
||||
@@ -137,7 +143,10 @@ it('gets rehydrated state from partial state', () => {
|
||||
{ key: 'baz-1', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
|
||||
],
|
||||
history: [{ type: 'route', key: 'qux-2' }],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar-0' },
|
||||
{ type: 'route', key: 'qux-2' },
|
||||
],
|
||||
stale: false,
|
||||
type: 'tab',
|
||||
});
|
||||
@@ -162,7 +171,10 @@ it('gets rehydrated state from partial state', () => {
|
||||
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
|
||||
],
|
||||
history: [{ type: 'route', key: 'qux-2' }],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar-0' },
|
||||
{ type: 'route', key: 'qux-2' },
|
||||
],
|
||||
stale: false,
|
||||
type: 'tab',
|
||||
});
|
||||
@@ -211,10 +223,7 @@ it('gets rehydrated state from partial state', () => {
|
||||
{ key: 'baz-test', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||
],
|
||||
history: [
|
||||
{ type: 'route', key: 'qux-test' },
|
||||
{ type: 'route', key: 'bar-test' },
|
||||
],
|
||||
history: [{ type: 'route', key: 'bar-test' }],
|
||||
stale: false,
|
||||
type: 'tab',
|
||||
});
|
||||
@@ -637,7 +646,10 @@ it('handles navigate action', () => {
|
||||
{ key: 'baz-1', name: 'baz' },
|
||||
{ key: 'bar-1', name: 'bar', params: { answer: 42 } },
|
||||
],
|
||||
history: [{ type: 'route', key: 'bar-1' }],
|
||||
history: [
|
||||
{ type: 'route', key: 'baz-1' },
|
||||
{ type: 'route', key: 'bar-1' },
|
||||
],
|
||||
});
|
||||
|
||||
expect(
|
||||
@@ -667,10 +679,7 @@ it('handles navigate action', () => {
|
||||
{ key: 'baz', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'bar', name: 'bar' },
|
||||
],
|
||||
history: [
|
||||
{ type: 'route', key: 'bar' },
|
||||
{ type: 'route', key: 'baz' },
|
||||
],
|
||||
history: [{ type: 'route', key: 'baz' }],
|
||||
});
|
||||
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user