Skip to content

Commit

Permalink
Fix issue to properly support navigating back by number
Browse files Browse the repository at this point in the history
  • Loading branch information
blainekasten committed Jul 9, 2020
1 parent 2083510 commit 9a23a55
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe(`navigation`, () => {
cy.location(`pathname`).should(`equal`, `/`)
})

it(`can navigate using numbers`, () => {
cy.getTestElement(`page-two`).click().waitForRouteChange()

cy.getTestElement(`back-by-number`).click()

cy.location(`pathname`).should(`equal`, `/`)
})

describe(`relative links`, () => {
it(`can navigate to a subdirectory`, () => {
cy.getTestElement(`subdir-link`)
Expand Down
4 changes: 4 additions & 0 deletions e2e-tests/development-runtime/src/pages/page-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link } from "gatsby"

import Layout from "../components/layout"
import SEO from "../components/seo"
import { navigate } from "gatsby"

const SecondPage = () => (
<Layout>
Expand All @@ -12,6 +13,9 @@ const SecondPage = () => (
<Link to="/" data-testid="back-button">
Go back to the homepage
</Link>
<button data-testid="back-by-number" onClick={() => navigate(-1)}>
Navigate by number back
</button>
</Layout>
)

Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-link/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function absolutify(path, current) {
}

const rewriteLinkPath = (path, relativeTo) => {
if (typeof path === `number`) {
return path
}
if (!isLocalLink(path)) {
return path
}
Expand Down

0 comments on commit 9a23a55

Please sign in to comment.