faustjs icon indicating copy to clipboard operation
faustjs copied to clipboard

How to get parameters on the URL

Open minhit1812 opened this issue 1 year ago • 4 comments

As the title, please show me how to get the value of the parameters on the URL in the variables For example, URL www.domain.com/archive/?page=1&order=asc I want to receive the value of the page=1 and order=asc to pass into Common.Query

Common.variables = ( seedQuery, ctx, extra ) => {
  const router = useRouter();
  const { page = 1 } = router.query ?? {};
  const offset = (Number(page) - 1) * Number(GET_LISTINGS_FIRST_COMMON);

  return {
    offset: offset,
    per_page: GET_LISTINGS_FIRST_COMMON,
    headerLocation: PRIMARY_LOCATION,
    footerLocation: FOOTER_LOCATION,
  };
};

minhit1812 avatar Dec 15 '23 05:12 minhit1812

Hey @minhit1812. If you are using getStaticProps then you won't be able to access the query parameters there since they are not available at build time. You will have to provide a getStaticPaths to gain access to them or use getServerSideProps.

https://github.com/vercel/next.js/discussions/17529

What is your use case here?

theodesp avatar Dec 15 '23 11:12 theodesp

Hi @theodesp. I know what you mean. I followed the example here https://github.com/wpengine/faustjs/blob/canary/examples/next/faustwp-getting-started/wp-templates/category.js

I would expect to receive a page value of the form domain.com/category/page/1 or something similar domain.com/category/?page=1 for pagination (I don't want to use Cursor-Based load more)

minhit1812 avatar Dec 16 '23 04:12 minhit1812

Hey @minhit1812 Thats correct. You should receive the value of the uri field of the SeedQuery. In my case was

http://localhost:3000/posts/category/uncategorized

What happened instead?

theodesp avatar Dec 19 '23 12:12 theodesp

@minhit1812 are you still having issues here?

mindctrl avatar Feb 06 '24 14:02 mindctrl

Hi @minhit1812! I'm going to close this issue for now. If you're still seeing the issue please do feel free to re-open it.

ChrisWiegman avatar Mar 14 '24 16:03 ChrisWiegman