Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle as on next/link with new router #41285

Merged
merged 2 commits into from Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/next/client/link.tsx
Expand Up @@ -182,7 +182,10 @@ function linkClicked(
// If `beforePopState` doesn't exist on the router it's the AppRouter.
const method: keyof AppRouterInstance = replace ? 'replace' : 'push'

router[method](href, { forceOptimisticNavigation: !prefetchEnabled })
// Apply `as` if it's provided.
router[method](as || href, {
forceOptimisticNavigation: !prefetchEnabled,
})
}
}

Expand Down
@@ -0,0 +1,9 @@
export default function Page({ params }) {
return (
<>
<p id="message">
hello from app/dashboard/deployments/info/[id]. ID is: {params.id}
</p>
</>
)
}
14 changes: 14 additions & 0 deletions test/e2e/app-dir/app/app/link-with-as/page.js
@@ -0,0 +1,14 @@
import Link from 'next/link'

export default function Page() {
return (
<>
<Link
href="/dashboard/deployments/info/[id]"
as="/dashboard/deployments/info/123"
>
<a id="link-to-info-123">To info 123</a>
</Link>
</>
)
}
10 changes: 10 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -1540,6 +1540,16 @@ describe('app dir', () => {
expect($('#category-id').text()).toBe('electronicsabc')
}
})
it('should handle as on next/link', async () => {
const browser = await webdriver(next.url, '/link-with-as')
expect(
await browser
.elementByCss('#link-to-info-123')
.click()
.waitForElementByCss('#message')
.text()
).toBe(`hello from app/dashboard/deployments/info/[id]. ID is: 123`)
})
})

describe('not-found', () => {
Expand Down