fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

Parameter 'url' must be a string, not undefined #65

Closed motleydev closed 7 years ago

motleydev commented 7 years ago

I have a serious of routes created that render to the page with named route properties. The rendered react looks like this:

<Link route="blog">
    <a onClick=bound linkClicked()>Blog</a>
</Link>

Which is defined by my menu.js component here:

import React from 'react'
import Link from 'next/link'
import {menu} from './routes'

export default () => (
  <ul>
    {
        menu.map( (menuchen, index) =>
        <li key={index}><Link route={menuchen.path}>
        <a>{menuchen.title}</a>
        </Link></li>)
    }
  </ul>
)

But when I click on the link the client console complains about a url parameter. Parameter 'url' must be a string, not undefined

I define the routes.js here:

const routes = module.exports.routes = require('next-routes')()

const menu = module.exports.menu = [
    {
        title: "Blog",
        path: "blog"
    }
]
menu.forEach(menuchen => {routes.add(menuchen.path, menu.path, "index")})

and my server.js setup looks like this:

const next = require('next')
const routes = require('./comps/menu/routes').routes
const app = next({dev: process.env.NODE_ENV !== 'production'})
const handler = routes.getRequestHandler(app)

const express = require('express')
app.prepare().then(() => {
  express().use(handler).listen(3000)
})
motleydev commented 7 years ago

Missed the part about importing <Link /> from the routes file. Needed some reconstruction but works now.