maccyber / next-custom-route-issue

Issue with custom route in now-dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Describe bug

I'm having troubles with custom routes in next.js when running through now dev

I have defined a custom route in now.json

  "routes": [
    { "src": "/product/(?<name>[^/]+)", "dest": "/product?name=$name" }
  ]

In pages/product.js query.name is passed from getInitialProps

Product.getInitialProps = async ({ query }) => {
  console.log(query.name || 'NOT FOUND') // returns "NOT FOUND" when accessing
                                         // http://localhost:3000/product/test
  return { name: query.name }
}

To Reproduce

git clone https://github.com/maccyber/next-custom-route-issue
npm i
now dev -d
open http://localhost:3000/product/test

About

Issue with custom route in now-dev


Languages

Language:JavaScript 100.0%