Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 9 additions & 5 deletions packages/react-router/src/fileRoute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRoute } from './route'
import { createRoute as createRouteImpl } from './route'

import { useMatch } from './useMatch'
import { useLoaderDeps } from './useLoaderDeps'
Expand Down Expand Up @@ -54,11 +54,15 @@ 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
const createRoute = (options?: any) => {
const route = createRouteImpl(options)
;(route as any).isRoot = false
return route
}
return createRoute as any
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

/**
Expand Down Expand Up @@ -151,7 +155,7 @@ export class FileRoute<
)
}
}
const route = createRoute(options as any)
const route = createRouteImpl(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
14 changes: 9 additions & 5 deletions packages/solid-router/src/fileRoute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRoute } from './route'
import { createRoute as createRouteImpl } from './route'

import { useMatch } from './useMatch'
import { useLoaderDeps } from './useLoaderDeps'
Expand Down Expand Up @@ -43,11 +43,15 @@ 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
const createRoute = (options?: any) => {
const route = createRouteImpl(options)
;(route as any).isRoot = false
return route
}
return createRoute as any
}

/**
Expand Down Expand Up @@ -140,7 +144,7 @@ export class FileRoute<
)
}
}
const route = createRoute(options as any)
const route = createRouteImpl(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
14 changes: 9 additions & 5 deletions packages/vue-router/src/fileRoute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRoute } from './route'
import { createRoute as createRouteImpl } from './route'

import { useMatch } from './useMatch'
import { useLoaderDeps } from './useLoaderDeps'
Expand Down Expand Up @@ -43,11 +43,15 @@ 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
const createRoute = (options?: any) => {
const route = createRouteImpl(options)
;(route as any).isRoot = false
return route
}
return createRoute as any
}

/**
Expand Down Expand Up @@ -140,7 +144,7 @@ export class FileRoute<
)
}
}
const route = createRoute(options as any)
const route = createRouteImpl(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