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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -56,7 +56,27 @@ For example, create the **app** directory in your project and then create a file | |||||||||||
|
||||||||||||
The above example matches the `/` route in the app and the browser. Files named **index** match the parent directory and do not add a path segment. For example, **app/settings/index.js** matches `/settings` in the app. | ||||||||||||
|
||||||||||||
> 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. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
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: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
<FileTree | ||||||||||||
files={[ | ||||||||||||
'app/_layout.js', | ||||||||||||
'app/_layout.web.js', | ||||||||||||
'app/index.js', | ||||||||||||
'app/about.js', | ||||||||||||
'app/about.web.js', | ||||||||||||
]} | ||||||||||||
/> | ||||||||||||
|
||||||||||||
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. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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. |
||||||||||||
|
||||||||||||
> **info** Always provide a file without a platform extension to ensure every platform has a default implementation. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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? |
||||||||||||
|
||||||||||||
## Dynamic routes | ||||||||||||
|
||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## Requests | ||||||
|
||||||
Requests use the global, standard [`Request`](https://fetch.spec.whatwg.org/#request) object. | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.