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

[router] rework unstable_settings.initialRouteName to unstable_settings.anchor #28644

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

marklawlor
Copy link
Contributor

Why

During normal navigation, the target screen will the initial route of a navigator. React Navigation allows users to disable this behaviour (via the initial: false option when dispatching a navigation event). When disabled, the navigator determines the index of the target route (e.g it might have an initialRouteName which will be used as the initial route).

I'm adding this as a feature, as it has both been requested and also is a stumbling block for new users.

How

  • Added a initial={Boolean} prop to <Link />
  • router.{navigate,push,replace}() now accepts a second options argument. The only option is { initialScreen: Boolean }

Test Plan

Updated unit tests

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label May 6, 2024
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels May 6, 2024
@marklawlor
Copy link
Contributor Author

marklawlor commented May 6, 2024

  • Swap behaviour
  • Add videos to documentation
  • unstable_ignoreAnchor
  • Update unstable_settings
    • anchor
  • Add deprecation warning

Copy link
Member

@amandeepmittal amandeepmittal left a comment

Choose a reason for hiding this comment

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

Lgtm 👍

Left a couple of docs related suggestions.

docs/pages/router/advanced/router-settings.mdx Outdated Show resolved Hide resolved
packages/expo-router/types/expo-router.d.ts Outdated Show resolved Hide resolved
@marklawlor marklawlor changed the title [router] add option to navigate to a route as a non-initial screen [router] rework unstable_settings.initialRouteName to unstable_settings.anchor May 8, 2024
@marklawlor marklawlor force-pushed the marklawlor/router/preverve-initial-screen branch 2 times, most recently from c591f81 to 7cfc92c Compare May 9, 2024 04:20
@@ -44,4 +44,13 @@ export const unstable_settings = {
};
```

The `initialRouteName` is only used when deep-linking to a route. During app navigation, the route you are navigating to will be the initial route. You can disable this behavior using the `initial` prop on the `<Link />` component or by passing the option to the imperative APIs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should add a notice about this in the migration doc for React Navigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint compatible bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants