Repository: TanStack/router (ts)

Issue:
Unexpected splitNode type ☝️: ConditionalExpression
### Which project does this relate to?

Router

### Describe the bug

I'm using a file-based router, and when attempting to write a conditional route (based on an external flag whether to enable the route), I'm running into this issue:

![Image](https://github.com/user-attachments/assets/62037bf8-f23d-4ebb-a50f-4161e7477e66)

Source code:
(Note: both `Calculator` and `Error404` are just really simple React components with no props)
```tsx
import { createFileRoute } from '@tanstack/react-router';
import { calculator } from '@config/config.json'; // This will be injected during build time via pipeline, but also available in dev mode
import Error404 from '@pages/Error/Error404';
import Calculator from '@pages/Calculator';


const { calculator: calculatorEnabled } = calculator;


export const Route = createFileRoute('/calculators')({
  component: calculatorEnabled ? Calculator : Error404,
});
```

### Your Example Website or App

https://stackblitz.com/edit/github-6p3psnjt?file=src%2Froutes%2Fconditional-route.tsx

### Steps to Reproduce the Bug or Issue

I tried to re-produce it but it's working in the stackblitz, I've no idea why...

### Expected behavior

It should work? Or it's just now allowed? But why it's working in stackblitz but not in my project😂

### Screenshots or Videos

See above

### Platform

Windows
Chrome 132
Tanstack packages: all LATEST

### Additional context

# ⚠️Attention
This is going to work, throws no Error at least. But I'm not sure how it's going to impact the code splitting.
```tsx
import { createFileRoute } from '@tanstack/react-router';
import { calculator } from '@config/config.json'; // This will be injected during build time via pipeline, but also available in dev mode
import Error404 from '@pages/Error/Error404';
import Calculator from '@pages/Calculator';


const { calculator: calculatorEnabled } = calculator;

const CalculatorPage = calculatorEnabled ? Calculator : Error404;

export const Route = createFileRoute('/calculators')({
  component: CalculatorPage,
});
```

Pull request description:
fix(router-plugin): handle "ConditionalExpression" when code-splitting
Closes #3353 

Patch:
diff --git a/packages/router-plugin/src/core/code-splitter/compilers.ts b/packages/router-plugin/src/core/code-splitter/compilers.ts
index 4ea24ae67..d12b6c223 100644
--- a/packages/router-plugin/src/core/code-splitter/compilers.ts
+++ b/packages/router-plugin/src/core/code-splitter/compilers.ts
@@ -511,6 +511,16 @@ export function compileCodeSplitVirtualRoute(
                   `Unexpected expression type encounter for "${SPLIT_TYPE}" in the node type "${splitNode.type}"`,
                 )
               }
+            } else if (t.isConditionalExpression(splitNode)) {
+              programPath.pushContainer(
+                'body',
+                t.variableDeclaration('const', [
+                  t.variableDeclarator(
+                    t.identifier(splitMeta.localExporterIdent),
+                    splitNode,
+                  ),
+                ]),
+              )
             } else {
               console.info('Unexpected splitNode type:', splitNode)
               throw new Error(`Unexpected splitNode type ☝️: ${splitNode.type}`)


Test patch:
diff --git a/packages/router-plugin/tests/code-splitter/snapshots/development/conditional-properties.tsx b/packages/router-plugin/tests/code-splitter/snapshots/development/conditional-properties.tsx
new file mode 100644
index 000000000..66e234f08
--- /dev/null
+++ b/packages/router-plugin/tests/code-splitter/snapshots/development/conditional-properties.tsx
@@ -0,0 +1,12 @@
+const $$splitLoaderImporter = () => import('conditional-properties.tsx?tsr-split');
+import { lazyFn } from '@tanstack/react-router';
+const $$splitComponentImporter = () => import('conditional-properties.tsx?tsr-split');
+import { lazyRouteComponent } from '@tanstack/react-router';
+import { createFileRoute } from '@tanstack/react-router';
+export const Route = createFileRoute('/posts')({
+  component: lazyRouteComponent($$splitComponentImporter, 'component', () => Route.ssr),
+  loader: lazyFn($$splitLoaderImporter, 'loader')
+});
+export function TSRDummyComponent() {
+  return null;
+}
\ No newline at end of file
diff --git a/packages/router-plugin/tests/code-splitter/snapshots/development/conditional-properties@split.tsx b/packages/router-plugin/tests/code-splitter/snapshots/development/conditional-properties@split.tsx
new file mode 100644
index 000000000..d483dd047
--- /dev/null
+++ b/packages/router-plugin/tests/code-splitter/snapshots/development/conditional-properties@split.tsx
@@ -0,0 +1,7 @@
+import { isEnabled } from '@features/feature-flags';
+import TrueImport from '@modules/true-component';
+import { FalseComponent, falseLoader } from '@modules/false-component';
+const SplitComponent = isEnabled ? TrueImport.Component : FalseComponent;
+export { SplitComponent as component };
+const SplitLoader = isEnabled ? TrueImport.loader : falseLoader;
+export { SplitLoader as loader };
\ No newline at end of file
diff --git a/packages/router-plugin/tests/code-splitter/snapshots/production/conditional-properties.tsx b/packages/router-plugin/tests/code-splitter/snapshots/production/conditional-properties.tsx
new file mode 100644
index 000000000..ae8ce80fc
--- /dev/null
+++ b/packages/router-plugin/tests/code-splitter/snapshots/production/conditional-properties.tsx
@@ -0,0 +1,9 @@
+const $$splitLoaderImporter = () => import('conditional-properties.tsx?tsr-split');
+import { lazyFn } from '@tanstack/react-router';
+const $$splitComponentImporter = () => import('conditional-properties.tsx?tsr-split');
+import { lazyRouteComponent } from '@tanstack/react-router';
+import { createFileRoute } from '@tanstack/react-router';
+export const Route = createFileRoute('/posts')({
+  component: lazyRouteComponent($$splitComponentImporter, 'component', () => Route.ssr),
+  loader: lazyFn($$splitLoaderImporter, 'loader')
+});
\ No newline at end of file
diff --git a/packages/router-plugin/tests/code-splitter/snapshots/production/conditional-properties@split.tsx b/packages/router-plugin/tests/code-splitter/snapshots/production/conditional-properties@split.tsx
new file mode 100644
index 000000000..d483dd047
--- /dev/null
+++ b/packages/router-plugin/tests/code-splitter/snapshots/production/conditional-properties@split.tsx
@@ -0,0 +1,7 @@
+import { isEnabled } from '@features/feature-flags';
+import TrueImport from '@modules/true-component';
+import { FalseComponent, falseLoader } from '@modules/false-component';
+const SplitComponent = isEnabled ? TrueImport.Component : FalseComponent;
+export { SplitComponent as component };
+const SplitLoader = isEnabled ? TrueImport.loader : falseLoader;
+export { SplitLoader as loader };
\ No newline at end of file
diff --git a/packages/router-plugin/tests/code-splitter/test-files/conditional-properties.tsx b/packages/router-plugin/tests/code-splitter/test-files/conditional-properties.tsx
new file mode 100644
index 000000000..6bd5ad6dd
--- /dev/null
+++ b/packages/router-plugin/tests/code-splitter/test-files/conditional-properties.tsx
@@ -0,0 +1,9 @@
+import { createFileRoute } from '@tanstack/react-router'
+import { isEnabled } from '@features/feature-flags'
+import TrueImport from '@modules/true-component'
+import { FalseComponent, falseLoader } from '@modules/false-component'
+
+export const Route = createFileRoute('/posts')({
+  component: isEnabled ? TrueImport.Component : FalseComponent,
+  loader: isEnabled ? TrueImport.loader : falseLoader,
+})