faustjs
faustjs copied to clipboard
How to get parameters on the URL
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,
};
};
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?
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)
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?
@minhit1812 are you still having issues here?
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.