首页 > 解决方案 > 将下一个 js 更新到 v9 后链接错误 - 参数 'url' 必须是字符串,而不是未定义

问题描述

我最近将我的nextJs项目更新到版本 9 。我使用next-routes包,像底部一样导出。

const routes = require('next-routes');

module.exports = routes()
    //******************************** structure of routes => {nameOfRoute, pattern  of route, page name inside pages folder } ************
    .add('homepage', '/', 'index')
    // **************************** Profile routes *******************************************************
    .add('dashboard', '/dashboard', 'dashboard/index')
    .add('profile_navigation', '/dashboard/profile/navigation', 'dashboard/profile/navigation')
    .add('profile_userInfo', '/dashboard/profile/user-information', 'dashboard/profile/userInfo')
    .add('profile_education', '/dashboard/profile/education', 'dashboard/profile/education')
    .add('profile_sendCV', '/dashboard/profile/send-cv', 'dashboard/profile/sendCV')
    .add('profile_skills', '/dashboard/profile/skills', 'dashboard/profile/skills')
    .add('profile_honorAndResearch', '/dashboard/profile/honor-and-research', 'dashboard/profile/honorAndResearch')
    .add('profile_language', '/dashboard/profile/language-skill', 'dashboard/profile/language')
    .add('profile_workExperience', '/dashboard/profile/work-experience', 'dashboard/profile/workExperience')
    .add('profile_profilePreview', '/dashboard/profile/preview', 'dashboard/profile/profileView')
    .add('profile_favoriteJobs', '/dashboard/profile/favorite-jobs', 'dashboard/profile/favoriteJobs')
    .add('profile_courses', '/dashboard/profile/courses', 'dashboard/profile/courses')

当我像这样使用链接时出现问题

import { Link } from '../../routes';
<Link route="dashboard">
   <a>Some text</a>
</Link>

我得到错误

Uncaught TypeError: Parameter 'url' must be a string, not undefined
at Url.push../node_modules/url/url.js.Url.parse (url.js:112)
at urlParse (url.js:106)
at Url.push../node_modules/url/url.js.Url.resolve (url.js:443)
at urlResolve (url.js:439)
at Link.getHref (link.js:8)
at Link.handleRef (link.js:8)
at ref (link.js:13)

标签: node.jsreactjsreact-routernext.jsvercel

解决方案


当我添加prefetch={false}到 Link 时,这对我来说没问题。

<Link href="YOUR_LINK" prefetch={false} />

在这里查看更多解释:https ://github.com/zeit/next.js/issues/8555


推荐阅读