Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/easy-zoos-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tanstack/react-router': patch
'@tanstack/solid-router': patch
'@tanstack/vue-router': patch
---

createFileRoute does not rely on FileRoute class
9 changes: 6 additions & 3 deletions packages/react-router/src/fileRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ export function createFileRoute<
TFullPath extends RouteConstraints['TFullPath'] =
FileRoutesByPath[TFilePath]['fullPath'],
>(
// eslint-disable-next-line unused-imports/no-unused-vars
path?: TFilePath,
): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {
return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {
silent: true,
}).createRoute
return (options) => {
const route = createRoute(options as any)
;(route as any).isRoot = false
return route as any
}
}

/**
Expand Down
27 changes: 26 additions & 1 deletion packages/react-router/tests/fileRoute.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
/* eslint-disable */
import { describe, it, expect } from 'vitest'
import { afterEach, describe, it, expect, vi } from 'vitest'
import {
getRouteApi,
createFileRoute,
createLazyRoute,
createLazyFileRoute,
LazyRoute,
AnyRoute,
FileRoute,
} from '../src'

afterEach(() => {
vi.restoreAllMocks()
})

describe('createFileRoute', () => {
it('creates a non-root route without a deprecation warning', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
// @ts-expect-error
const route = createFileRoute('')({})

expect(route.isRoot).toBe(false)
expect(warn).not.toHaveBeenCalled()
})

it('keeps the deprecation warning for direct FileRoute usage', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
// @ts-expect-error
const route = new FileRoute('').createRoute({})

expect(route.isRoot).toBe(false)
expect(warn).toHaveBeenCalledOnce()
})
})

describe('createFileRoute has the same hooks as getRouteApi', () => {
const routeApi = getRouteApi('foo')
const hookNames = Object.keys(routeApi).filter((key) => key.startsWith('use'))
Expand Down
9 changes: 6 additions & 3 deletions packages/solid-router/src/fileRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ export function createFileRoute<
TFullPath extends RouteConstraints['TFullPath'] =
FileRoutesByPath[TFilePath]['fullPath'],
>(
// eslint-disable-next-line unused-imports/no-unused-vars
path?: TFilePath,
): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {
return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {
silent: true,
}).createRoute
return (options) => {
const route = createRoute(options as any)
;(route as any).isRoot = false
return route as any
}
}

/**
Expand Down
27 changes: 26 additions & 1 deletion packages/solid-router/tests/fileRoute.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
/* eslint-disable */
import { describe, it, expect } from 'vitest'
import { afterEach, describe, it, expect, vi } from 'vitest'
import {
getRouteApi,
createFileRoute,
createLazyRoute,
createLazyFileRoute,
LazyRoute,
FileRoute,
} from '../src'

afterEach(() => {
vi.restoreAllMocks()
})

describe('createFileRoute', () => {
it('creates a non-root route without a deprecation warning', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
// @ts-expect-error
const route = createFileRoute('')({})

expect(route.isRoot).toBe(false)
expect(warn).not.toHaveBeenCalled()
})

it('keeps the deprecation warning for direct FileRoute usage', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
// @ts-expect-error
const route = new FileRoute('').createRoute({})

expect(route.isRoot).toBe(false)
expect(warn).toHaveBeenCalledOnce()
})
})

describe('createFileRoute has the same hooks as getRouteApi', () => {
const routeApi = getRouteApi('foo')
const hookNames = Object.keys(routeApi).filter((key) => key.startsWith('use'))
Expand Down
9 changes: 6 additions & 3 deletions packages/vue-router/src/fileRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ export function createFileRoute<
TFullPath extends RouteConstraints['TFullPath'] =
FileRoutesByPath[TFilePath]['fullPath'],
>(
// eslint-disable-next-line unused-imports/no-unused-vars
path?: TFilePath,
): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {
return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {
silent: true,
}).createRoute
return (options) => {
const route = createRoute(options as any)
;(route as any).isRoot = false
return route as any
}
}

/**
Expand Down
27 changes: 26 additions & 1 deletion packages/vue-router/tests/fileRoute.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
/* eslint-disable */
import { describe, it, expect } from 'vitest'
import { afterEach, describe, it, expect, vi } from 'vitest'
import {
getRouteApi,
createFileRoute,
createLazyRoute,
createLazyFileRoute,
LazyRoute,
FileRoute,
} from '../src'

afterEach(() => {
vi.restoreAllMocks()
})

describe('createFileRoute', () => {
it('creates a non-root route without a deprecation warning', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
// @ts-expect-error
const route = createFileRoute('')({})

expect(route.isRoot).toBe(false)
expect(warn).not.toHaveBeenCalled()
})

it('keeps the deprecation warning for direct FileRoute usage', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
// @ts-expect-error
const route = new FileRoute('').createRoute({})

expect(route.isRoot).toBe(false)
expect(warn).toHaveBeenCalledOnce()
})
})

describe('createFileRoute has the same hooks as getRouteApi', () => {
const routeApi = getRouteApi('foo')
const hookNames = Object.keys(routeApi).filter((key) => key.startsWith('use'))
Expand Down
Loading