1

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.

Hamza El Aoutar
  • 5,292
  • 2
  • 17
  • 23
Alexander Hemming
  • 753
  • 1
  • 6
  • 28
  • `console.log(router)` see what that brings up – Kamran Nazir Oct 11 '19 at 12:43
  • console.log(router) VM38:1 Uncaught ReferenceError: router is not defined at :1:13 does not seem to be available – Alexander Hemming Oct 11 '19 at 16:48
  • instead of writing it console could you write this console line in your code, i.e. right after `const router = useRouter();` – warl0ck Oct 11 '19 at 18:51
  • THe console doesnt vie anything when i do this. Further there is this in the console: index.js:1 Fetch API cannot load file:///C:/WINDOWS/system32/next-learn-demo/8-deploying/node_modules/next/dist/client/router.js. URL scheme must be "http" or "https" for CORS request. Suggesting that it is not loading for that reason, along with 5 other api fetch requests – Alexander Hemming Oct 15 '19 at 13:04
  • https://stackoverflow.com/questions/50445639/fetch-api-cannot-load-file-c-users-woshi-desktop-p5-p5-json-birds-json-url – Alexander Hemming Nov 02 '19 at 04:30

1 Answers1

1

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
Yilmaz
  • 35,338
  • 10
  • 157
  • 202