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
21 changes: 19 additions & 2 deletions e2e/react-start/basic/src/routes/specialChars/hash.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import { createFileRoute, useLocation } from '@tanstack/react-router'
import { useState } from 'react'

export const Route = createFileRoute('/specialChars/hash')({
component: RouteComponent,
})

function RouteComponent() {
const l = useLocation()
const [toggleHashValue, setToggleHashValue] = useState(false)
return (
<div data-testid="special-hash-heading">
Hello "/specialChars/hash"!
<span data-testid="special-hash">{l.hash}</span>
<div>Hello "/specialChars/hash"!</div>
<button
className={
'mt-2 mb-2 px-1 py-1 bg-indigo-600 text-white rounded hover:bg-indigo-700 transition duration-200'
}
data-testid="toggle-hash-button"
onClick={() => setToggleHashValue(!toggleHashValue)}
>
Toggle HashValue
</button>
<div>
{toggleHashValue && (
<div>
Hash Value<span data-testid="special-hash">{l.hash}</span>
</div>
)}
</div>
</div>
)
}
22 changes: 14 additions & 8 deletions e2e/react-start/basic/tests/special-characters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test.describe('Unicode route rendering', () => {
page,
baseURL,
}) => {
await expect(page.getByTestId('special-hash-link')).not.toHaveClass(
await expect(page.getByTestId('special-hash-link')).not.toContainClass(
'font-bold',
)
await page.goto('/specialChars/hash#대|')
Expand All @@ -118,19 +118,22 @@ test.describe('Unicode route rendering', () => {

await expect(page.getByTestId('special-hash-heading')).toBeInViewport()

const hashValue = await page.getByTestId('special-hash').textContent()

await expect(page.getByTestId('special-hash-link')).toHaveClass(
await expect(page.getByTestId('special-hash-link')).toContainClass(
'font-bold',
)

await page.getByTestId('toggle-hash-button').click()

const hashValue = await page.getByTestId('special-hash').textContent()

expect(hashValue).toBe('대|')
})

test('should render route correctly on router navigation', async ({
page,
baseURL,
}) => {
await expect(page.getByTestId('special-hash-link')).not.toHaveClass(
await expect(page.getByTestId('special-hash-link')).not.toContainClass(
'font-bold',
)
const link = page.getByTestId('special-hash-link')
Expand All @@ -142,11 +145,14 @@ test.describe('Unicode route rendering', () => {

await expect(page.getByTestId('special-hash-heading')).toBeInViewport()

const hashValue = await page.getByTestId('special-hash').textContent()

await expect(page.getByTestId('special-hash-link')).toHaveClass(
await expect(page.getByTestId('special-hash-link')).toContainClass(
'font-bold',
)

await page.getByTestId('toggle-hash-button').click()

const hashValue = await page.getByTestId('special-hash').textContent()

expect(hashValue).toBe('대|')
})
})
Expand Down
27 changes: 19 additions & 8 deletions e2e/solid-start/basic/src/routes/specialChars/hash.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import { createFileRoute, useLocation } from '@tanstack/solid-router'
import { createEffect, createSignal } from 'solid-js'
import { createSignal } from 'solid-js'

export const Route = createFileRoute('/specialChars/hash')({
component: RouteComponent,
})

function RouteComponent() {
const location = useLocation()
const [getHash, setHash] = createSignal('')

createEffect(() => {
setHash(location().hash)
})
const [toggleHashValue, setToggleHashValue] = createSignal(false)

return (
<div data-testid="special-hash-heading">
Hello "/specialChars/hash"!
<span data-testid="special-hash">{getHash()}</span>
<div>Hello "/specialChars/hash"!</div>
<button
class={
'mt-2 mb-2 px-1 py-1 bg-indigo-600 text-white rounded hover:bg-indigo-700 transition duration-200'
}
data-testid="toggle-hash-button"
onClick={() => setToggleHashValue(!toggleHashValue())}
>
Toggle HashValue
</button>
<div>
{toggleHashValue() && (
<div>
Hash Value<span data-testid="special-hash">{location().hash}</span>
</div>
)}
</div>
</div>
)
}
23 changes: 13 additions & 10 deletions e2e/solid-start/basic/tests/special-characters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test.describe('Unicode route rendering', () => {
page,
baseURL,
}) => {
await expect(page.getByTestId('special-hash-link')).not.toHaveClass(
await expect(page.getByTestId('special-hash-link')).not.toContainClass(
'font-bold',
)
await page.goto('/specialChars/hash#대|')
Expand All @@ -118,13 +118,13 @@ test.describe('Unicode route rendering', () => {

await expect(page.getByTestId('special-hash-heading')).toBeInViewport()

const hashValue = await page.getByTestId('special-hash').textContent()
await expect(page.getByTestId('special-hash-link')).toContainClass(
'font-bold',
)

const el = await page
.getByTestId('special-hash-link')
.evaluate((e) => e.classList.value)
await page.getByTestId('toggle-hash-button').click()

expect(el).toContain('font-bold')
const hashValue = await page.getByTestId('special-hash').textContent()

expect(hashValue).toBe('대|')
})
Expand All @@ -133,7 +133,7 @@ test.describe('Unicode route rendering', () => {
page,
baseURL,
}) => {
await expect(page.getByTestId('special-hash-link')).not.toHaveClass(
await expect(page.getByTestId('special-hash-link')).not.toContainClass(
'font-bold',
)
const link = page.getByTestId('special-hash-link')
Expand All @@ -145,11 +145,14 @@ test.describe('Unicode route rendering', () => {

await expect(page.getByTestId('special-hash-heading')).toBeInViewport()

const hashValue = await page.getByTestId('special-hash').textContent()

await expect(page.getByTestId('special-hash-link')).toHaveClass(
await expect(page.getByTestId('special-hash-link')).toContainClass(
'font-bold',
)

await page.getByTestId('toggle-hash-button').click()

const hashValue = await page.getByTestId('special-hash').textContent()

expect(hashValue).toBe('대|')
})
})
Expand Down
44 changes: 34 additions & 10 deletions e2e/vue-start/basic/src/routes/specialChars/hash.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
import { createFileRoute, useLocation } from '@tanstack/vue-router'
import { defineComponent, ref } from 'vue'

const RouteComponent = defineComponent({
setup() {
const l = useLocation()
const toggleHashValue = ref(false)

const toggle = () => {
toggleHashValue.value = !toggleHashValue.value
}

return () => (
<div data-testid="special-hash-heading">
<div>Hello "/specialChars/hash"!</div>
<button
class={
'mt-2 mb-2 px-1 py-1 bg-indigo-600 text-white rounded hover:bg-indigo-700 transition duration-200'
}
data-testid="toggle-hash-button"
onClick={toggle}
>
Toggle HashValue
</button>
<div>
{toggleHashValue.value && (
<div>
Hash Value<span data-testid="special-hash">{l.value.hash}</span>
</div>
)}
</div>
</div>
)
},
})

export const Route = createFileRoute('/specialChars/hash')({
component: RouteComponent,
})

function RouteComponent() {
const l = useLocation()
return (
<div data-testid="special-hash-heading">
Hello "/specialChars/hash"!
<span data-testid="special-hash">{l.value.hash}</span>
</div>
)
}
22 changes: 14 additions & 8 deletions e2e/vue-start/basic/tests/special-characters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test.describe('Unicode route rendering', () => {
page,
baseURL,
}) => {
await expect(page.getByTestId('special-hash-link')).not.toHaveClass(
await expect(page.getByTestId('special-hash-link')).not.toContainClass(
'font-bold',
)
await page.goto('/specialChars/hash#대|')
Expand All @@ -118,19 +118,22 @@ test.describe('Unicode route rendering', () => {

await expect(page.getByTestId('special-hash-heading')).toBeInViewport()

const hashValue = await page.getByTestId('special-hash').textContent()

await expect(page.getByTestId('special-hash-link')).toHaveClass(
await expect(page.getByTestId('special-hash-link')).toContainClass(
'font-bold',
)

await page.getByTestId('toggle-hash-button').click()

const hashValue = await page.getByTestId('special-hash').textContent()

expect(hashValue).toBe('대|')
})

test('should render route correctly on router navigation', async ({
page,
baseURL,
}) => {
await expect(page.getByTestId('special-hash-link')).not.toHaveClass(
await expect(page.getByTestId('special-hash-link')).not.toContainClass(
'font-bold',
)
const link = page.getByTestId('special-hash-link')
Expand All @@ -142,11 +145,14 @@ test.describe('Unicode route rendering', () => {

await expect(page.getByTestId('special-hash-heading')).toBeInViewport()

const hashValue = await page.getByTestId('special-hash').textContent()

await expect(page.getByTestId('special-hash-link')).toHaveClass(
await expect(page.getByTestId('special-hash-link')).toContainClass(
'font-bold',
)

await page.getByTestId('toggle-hash-button').click()

const hashValue = await page.getByTestId('special-hash').textContent()

expect(hashValue).toBe('대|')
})
})
Expand Down
8 changes: 7 additions & 1 deletion packages/react-router/src/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export function useLinkProps<
structuralSharing: true as any,
})

// subscribe to href to re-build location if it changes
const currentHash = useRouterState({
select: (s) => s.location.hash,
structuralSharing: true as any,
})

Comment thread
nlynzaad marked this conversation as resolved.
Outdated
const from = options.from

const _options = React.useMemo(
Expand Down Expand Up @@ -219,7 +225,7 @@ export function useLinkProps<
}
}

if (activeOptions?.includeHash) {
if (activeOptions?.includeHash && !router.isServer) {
return s.location.hash === next.hash
}
return true
Expand Down
Loading