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] add platform extension docs #27409

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

Conversation

marklawlor
Copy link
Contributor

Why

Add docs for #27408. Version numbers are placeholder values

How

Test Plan

Checklist

@expo-bot expo-bot added the bot: passed checks ExpoBot has nothing to complain about label Mar 4, 2024
@marklawlor

This comment was marked as outdated.

@marklawlor marklawlor closed this Mar 6, 2024
@marklawlor marklawlor reopened this Mar 6, 2024
Co-authored-by: Evan Bacon <bacon@expo.io>
@marklawlor marklawlor marked this pull request as ready for review April 15, 2024 05:04
@@ -3,6 +3,8 @@ title: Platform-specific Modules
description: Learn how to switch modules based on the platform in Expo Router.
---

> **warning** Platform specific extensions were added in Expo Router 3.x.x. This guide is only needed if you are using an older version of Expo Router.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> **warning** Platform specific extensions were added in Expo Router 3.x.x. This guide is only needed if you are using an older version of Expo Router.
> **warning** Platform specific extensions were added in Expo Router `3.x.x`. Follow this guide only if you are using an older version of Expo Router.

> Platform extensions (for example, **.ios.js**, **.native.ts**) are not supported in the **app** directory. See [Platform-specific modules](/router/advanced/platform-specific-modules), for more information.
## Platform specific extensions

> **warning** Platform-specific extensions were added in Expo Router 3.x.x. If you are using an older version, please see [Platform-specific modules](/router/advanced/platform-specific-modules), for more information.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> **warning** Platform-specific extensions were added in Expo Router 3.x.x. If you are using an older version, please see [Platform-specific modules](/router/advanced/platform-specific-modules), for more information.
> **warning** Platform-specific extensions were added in Expo Router `3.x.x`. If you are using an older version of the library, follow instructions from [Platform-specific modules](/router/advanced/platform-specific-modules).


Metro bundler's platform-specific extensions (for example, **.ios.js** or **.native.ts**) are supported in the **app** directory only if a **non-platform version** also exists. This ensures that routes are universal across platforms for deep linking.

Consider the following project:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Consider the following project:
Consider the following project structure:

]}
/>

In this project, the **\_layout.web.js** file is used as a layout on the web and **\_layout.js** is used on all other platform. The **index.js** file is used as the home page for all platforms. The **about.web.js** file is used as the about page for the web and **about.js** file is used on all other platforms.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In this project, the **\_layout.web.js** file is used as a layout on the web and **\_layout.js** is used on all other platform. The **index.js** file is used as the home page for all platforms. The **about.web.js** file is used as the about page for the web and **about.js** file is used on all other platforms.
In the above file structure:
- **\_layout.web.js** file is used as a layout on the web and **\_layout.js** is used on all other platforms.
- **index.js** file is used as the home page for all platforms.
- **about.web.js** file is used as the about page for the web, and the **about.js** file is used on all other platforms.

There's a lot going on in the above paragraph, let's convert it to a list of items. Plus, also fix a couple typos.

@@ -104,6 +104,8 @@ Deploy the website and server to a [hosting provider](#deployment) to access the

</Step>

> **warning** API routes filenames cannot have platform specific extensions. For example, `hello+api.web.ts` will not work.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> **warning** API routes filenames cannot have platform specific extensions. For example, `hello+api.web.ts` will not work.
> **warning** API route filenames cannot have platform-specific extensions. For example, **hello+api.web.ts** will not work.


In this project, the **\_layout.web.js** file is used as a layout on the web and **\_layout.js** is used on all other platform. The **index.js** file is used as the home page for all platforms. The **about.web.js** file is used as the about page for the web and **about.js** file is used on all other platforms.

> **info** Always provide a file without a platform extension to ensure every platform has a default implementation.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> **info** Always provide a file without a platform extension to ensure every platform has a default implementation.
> **info** Providing a route file without a platform-specific extension is required to ensure every platform has a default implementation.

Since in the first paragraph we say this is requirement for Metro bundler to recognize a platform specific extension only if non-platform specific extension exits, let's say it like that here. Since this is a callout, we can be authoritative and clear about this.

Also, what does "default implementation" mean here? is it the layout? or the home screen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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