简体   繁体   中英

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".Even though in the stages afterwards on stages 3 to 8 the dynamic routing should already be working.

What i assumed was the problems is that the file.next/routing appeared to be missing.

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

Why is the routing file not in the.next folder?

the react version is 16.10.2 (installed today through tutorial instructions) the format of code is what is in the tutorial copy pasted. (no hook rule breaking) there are no react duplicates.

I think you are using useRouter() in class component. useRouter is a hook and used only in functional components.

in class components we use withRouter HOC. "router" object is accessible as

this.props.router

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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