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): remove not-found param from web url on not found pages #25955

Merged
merged 8 commits into from
Dec 18, 2023

Conversation

marklawlor
Copy link
Contributor

Why

ENG-10875

Remove the not-found param from web URLs

How

When converting State->Path we use matchDeepDynamicRouteName to extract catch-all route param names, and ensure these are not serialised in the URL.

While +not-found had the correct route pattern, our logic is going off the route name which does match the regex

I added a special condition instead of updating the regex.

export function matchDeepDynamicRouteName(name: string): string | undefined {
return name.match(/^\[\.\.\.([^/]+?)\]$/)?.[1];
}

Test Plan

We had an existing test giving a false positive due to an incorrect pattern for the +not-found route

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Dec 15, 2023
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Dec 15, 2023
@@ -525,7 +525,8 @@ function getParamsWithConventionsCollapsed({
// Deep Dynamic Routes
if (segments.some((segment) => segment.startsWith('*'))) {
// NOTE(EvanBacon): Drop the param name matching the wildcard route name -- this is specific to Expo Router.
const name = matchDeepDynamicRouteName(routeName) ?? routeName;
const name =
routeName === '+not-found' ? 'not-found' : matchDeepDynamicRouteName(routeName) ?? routeName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work with nested not-found, e.g. foo/+not-found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix this and updated the PR with extra tests.

I added a new matcher getPathnameWithParams that allows you to assert what the pathname is with the query parameters.

@marklawlor
Copy link
Contributor Author

@EvanBacon While working on this PR I noticed that global parameters for catchall routes where not being properly decoded. Currently the parameters for catch all routes are joined to a comma separated list. That was causing these new tests to fail

I fixed the issue and updated the other affected tests. We had tests around this, but they were ineffective as they simply tested single values for catch all routes. I've updated these tests to use a variety of single and multiple values.

@marklawlor marklawlor merged commit 0c64ba3 into main Dec 18, 2023
12 checks passed
@marklawlor marklawlor deleted the marklawlor/expo-router/not-found-web-param branch December 18, 2023 23:56
onizam95 pushed a commit to onizam95/expo-av-drm that referenced this pull request Jan 15, 2024
…o#25955)

# Why

[ENG-10875](https://linear.app/expo/issue/ENG-10875)

Remove the `not-found` param from web URLs

# How

When converting State->Path we use `matchDeepDynamicRouteName` to
extract catch-all route param names, and ensure these are not serialised
in the URL.

While `+not-found` had the correct route pattern, our logic is going off
the route name which does match the regex

I added a special condition instead of updating the regex.


https://github.com/expo/expo/blob/3e255470c5bff458883a75fe5b956d89147fa1b5/packages/expo-router/src/matchers.tsx#L9-L11

# Test Plan

We had an existing test giving a false positive due to an incorrect
pattern for the `+not-found` route

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint changed bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants