Skip to content

Commit 8277d43

Browse files
authored
Rewrite url when exporting only if there's a href. (vercel#2316)
1 parent 7b8a4ea commit 8277d43

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

lib/link.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export default class Link extends Component {
129129
// Add the ending slash to the paths. So, we can serve the
130130
// "<page>/index.html" directly.
131131
if (
132+
props.href &&
132133
typeof __NEXT_DATA__ !== 'undefined' &&
133134
__NEXT_DATA__.nextExport
134135
) {

test/integration/static/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
return {
44
'/': { page: '/' },
55
'/about': { page: '/about' },
6+
'/button-link': { page: '/button-link' },
67
'/get-initial-props-with-no-query': { page: '/get-initial-props-with-no-query' },
78
'/counter': { page: '/counter' },
89
'/dynamic-imports': { page: '/dynamic-imports' },
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Link from 'next/link'
2+
3+
export default () => (
4+
<div id='button-link-page'>
5+
<div>
6+
<Link href='/'>
7+
<button>Go Back</button>
8+
</Link>
9+
</div>
10+
<p>This is the About page</p>
11+
</div>
12+
)

test/integration/static/test/browser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ export default function (context) {
135135
browser.close()
136136
})
137137

138+
it('should navigate even if used a button inside <Link />', async () => {
139+
const browser = await webdriver(context.port, '/button-link')
140+
141+
const text = await browser
142+
.elementByCss('button').click()
143+
.waitForElementByCss('#home-page')
144+
.elementByCss('#home-page p').text()
145+
146+
expect(text).toBe('This is the home page')
147+
browser.close()
148+
})
149+
138150
describe('pages in the nested level: level1', () => {
139151
it('should render the home page', async () => {
140152
const browser = await webdriver(context.port, '/')

yarn.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5319,7 +5319,11 @@ utils-merge@1.0.0:
53195319
version "1.0.0"
53205320
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.0.tgz#0294fb922bb9375153541c4f7096231f287c8af8"
53215321

5322-
uuid@3.0.1, uuid@^3.0.0:
5322+
uuid@3.1.0:
5323+
version "3.1.0"
5324+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"
5325+
5326+
uuid@^3.0.0:
53235327
version "3.0.1"
53245328
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"
53255329

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy