Skip to content

Commit

Permalink
fix(gatsby): use route path to serve _exact_ page in client routing (#…
Browse files Browse the repository at this point in the history
…11740)

* fix(gatsby): use route path to serve _exact_ page in client routing

* chore: rename declaration (whoops)
  • Loading branch information
DSchau authored and sidharthachatterjee committed Feb 19, 2019
1 parent 2396099 commit a680e69
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/gatsby/src/commands/serve.js
Expand Up @@ -17,18 +17,23 @@ const getPages = directory =>
.catch(() => [])

const clientOnlyPathsRouter = (pages, options) => {
const clientOnlyRoutes = pages
.filter(page => page.matchPath)
.map(page => page.matchPath)
const clientOnlyRoutes = pages.filter(page => page.matchPath)
return (req, res, next) => {
const { url } = req
if (req.accepts(`html`)) {
if (clientOnlyRoutes.some(route => reachMatch(route, url) !== null)) {
return res.sendFile(`index.html`, options, err => {
if (err) {
next()
const route = clientOnlyRoutes.find(
clientRoute => reachMatch(clientRoute.matchPath, url) !== null
)
if (route && route.path) {
return res.sendFile(
path.join(route.path, `index.html`),
options,
err => {
if (err) {
next()
}
}
})
)
}
}
return next()
Expand Down

0 comments on commit a680e69

Please sign in to comment.