简体   繁体   English

网站教程中Next.js路由错误

[英]Next.js routing error in website tutorial

For me the next.js tutorial https://github.com/zeit/next-learn-demo.git has a problem at all stages past stage 2 "dynamic routing".对我来说,next.js 教程https://github.com/zeit/next-learn-demo.git在第 2 阶段之后的所有阶段都有问题。“动态路由Even though in the stages afterwards on stages 3 to 8 the dynamic routing should already be working.即使在之后的阶段 3 到 8 的阶段中,动态路由应该已经开始工作了。

What i assumed was the problems is that the file.next/routing appeared to be missing.我假设的问题是 file.next/routing 似乎丢失了。

As such the tutorial asked implementation of code:因此,本教程要求实现代码:

import { useRouter } from 'next/router';

and

const router = useRouter();

does not do anything.不做任何事情。

leading to the error on clicking the link:导致点击链接出错:

screenshot of next.js browser syntax error inspection next.js浏览器语法错误检查截图

Why is the routing file not in the.next folder?为什么路由文件不在.next文件夹中?

the react version is 16.10.2 (installed today through tutorial instructions) the format of code is what is in the tutorial copy pasted.反应版本是 16.10.2(今天通过教程说明安装)代码格式是教程复制粘贴的内容。 (no hook rule breaking) there are no react duplicates. (没有破坏钩子规则)没有反应重复。

I think you are using useRouter() in class component.我认为您在 class 组件中使用了 useRouter() 。 useRouter is a hook and used only in functional components. useRouter 是一个钩子,仅在功能组件中使用。

in class components we use withRouter HOC.在 class 组件中,我们与路由器 HOC 一起使用。 "router" object is accessible as “路由器” object 可访问为

this.props.router

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM