Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get URL query string on Next.js static site generation?

I want to get query string from URL on Next.js static site generation.

I found a solution on SSR but I need one for SSG.

Thanks

enter image description here

like image 562
Raju Ahammad Avatar asked Mar 02 '23 17:03

Raju Ahammad


1 Answers

import { useRouter } from "next/router";
import { useEffect } from "react";

const router = useRouter();

useEffect(() => {
    if(!router.isReady) return;
    const query = router.query;
  }, [router.isReady, router.query]);

It works.

like image 53
Umut Çiftci Avatar answered Apr 01 '23 04:04

Umut Çiftci