Skip to content

Commit

Permalink
add flag to disable platform routes
Browse files Browse the repository at this point in the history
  • Loading branch information
marklawlor committed Apr 15, 2024
1 parent 9734cad commit 6822c01
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/expo-router/build/getRoutes.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion packages/expo-router/build/getRoutes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-router/build/getRoutes.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/expo-router/plugin/options.json
Expand Up @@ -40,6 +40,10 @@
"description": "Changes the routes directory from `app` to another value. Defaults to `app`. Avoid using this property.",
"type": "string"
},
"platformRoutes": {
"description": "Enable or disable platform-specific routes. Defaults to `true`.",
"type": "boolean"
},
"asyncRoutes": {
"description": "Should Async Routes be enabled. `production` is currently web-only and will be disabled on native.",
"oneOf": [
Expand Down
9 changes: 8 additions & 1 deletion packages/expo-router/src/getRoutes.ts
@@ -1,3 +1,5 @@
import Constants from 'expo-constants';

import { DynamicConvention, RouteNode } from './Route';
import {
matchArrayGroupName,
Expand Down Expand Up @@ -28,6 +30,7 @@ type DirectoryNode = {
};

const validPlatforms = new Set(['android', 'ios', 'native', 'web']);
const hasPlatformRoutes = Constants.expoConfig?.extra?.router?.platformRoutes ?? true;

/**
* Given a Metro context module, return an array of nested routes.
Expand Down Expand Up @@ -350,11 +353,15 @@ function getFileMeta(key: string, options: Options) {
);
}
let specificity = 0;

const platformExtension = filenameWithoutExtensions.split('.')[1];
const hasPlatformExtension = validPlatforms.has(platformExtension);

if (hasPlatformExtension) {
if (!options.platform) {
if (!hasPlatformRoutes) {
// If the user has disabled platform routes, then we should ignore this file
specificity = -1;
} else if (!options.platform) {
// If we don't have a platform, then we should ignore this file
// This used by typed routes, sitemap, etc
specificity = -1;
Expand Down

0 comments on commit 6822c01

Please sign in to comment.