From 8277d43190942feeccc692e37a8ba85fa431f163 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Tue, 20 Jun 2017 14:07:36 +0530 Subject: [PATCH] Rewrite url when exporting only if there's a href. (#2316) --- lib/link.js | 1 + test/integration/static/next.config.js | 1 + test/integration/static/pages/button-link.js | 12 ++++++++++++ test/integration/static/test/browser.js | 12 ++++++++++++ yarn.lock | 6 +++++- 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/integration/static/pages/button-link.js diff --git a/lib/link.js b/lib/link.js index 4b3e271e..8fb9b2e8 100644 --- a/lib/link.js +++ b/lib/link.js @@ -129,6 +129,7 @@ export default class Link extends Component { // Add the ending slash to the paths. So, we can serve the // "/index.html" directly. if ( + props.href && typeof __NEXT_DATA__ !== 'undefined' && __NEXT_DATA__.nextExport ) { diff --git a/test/integration/static/next.config.js b/test/integration/static/next.config.js index 416a77de..7c6fa0f9 100644 --- a/test/integration/static/next.config.js +++ b/test/integration/static/next.config.js @@ -3,6 +3,7 @@ module.exports = { return { '/': { page: '/' }, '/about': { page: '/about' }, + '/button-link': { page: '/button-link' }, '/get-initial-props-with-no-query': { page: '/get-initial-props-with-no-query' }, '/counter': { page: '/counter' }, '/dynamic-imports': { page: '/dynamic-imports' }, diff --git a/test/integration/static/pages/button-link.js b/test/integration/static/pages/button-link.js new file mode 100644 index 00000000..81b58e3a --- /dev/null +++ b/test/integration/static/pages/button-link.js @@ -0,0 +1,12 @@ +import Link from 'next/link' + +export default () => ( + +) diff --git a/test/integration/static/test/browser.js b/test/integration/static/test/browser.js index 23d56e0e..c7d5b7f9 100644 --- a/test/integration/static/test/browser.js +++ b/test/integration/static/test/browser.js @@ -135,6 +135,18 @@ export default function (context) { browser.close() }) + it('should navigate even if used a button inside ', async () => { + const browser = await webdriver(context.port, '/button-link') + + const text = await browser + .elementByCss('button').click() + .waitForElementByCss('#home-page') + .elementByCss('#home-page p').text() + + expect(text).toBe('This is the home page') + browser.close() + }) + describe('pages in the nested level: level1', () => { it('should render the home page', async () => { const browser = await webdriver(context.port, '/') diff --git a/yarn.lock b/yarn.lock index 2f0922f4..76b13db5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5319,7 +5319,11 @@ utils-merge@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.0.tgz#0294fb922bb9375153541c4f7096231f287c8af8" -uuid@3.0.1, uuid@^3.0.0: +uuid@3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04" + +uuid@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"