Add dynamic route parameter getter in edge functions #40468
artrixdotdev
started this conversation in
Ideas
Replies: 4 comments 3 replies
-
any updates on this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
? |
Beta Was this translation helpful? Give feedback.
0 replies
-
It's not documented but actually the query is assigned to import { NextRequest } from "next/server";
export const config = { runtime: "experimental-edge" };
export default async function handler(req: NextRequest) {
return new Response(JSON.stringify({ url: req.url }));
} // GET http://localhost:3000/api/dynamic/hello/world/c
{"url": "http://localhost:3000/api/dynamic/hello/world/c?a=hello&b=world"} So you can do import { NextRequest } from "next/server";
export const config = { runtime: "experimental-edge" };
export default async function handler(req: NextRequest) {
const params = new URL(req.url).searchParams;
const a = params.get("a");
const b = params.get("b");
return new Response(JSON.stringify({ a, b }));
} to get {"a":"hello","b":"world"} |
Beta Was this translation helpful? Give feedback.
2 replies
-
You don't need to parse it with const locale = req.nextUrl.searchParams.get("locale") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the feature you'd like to request
So currently in the following file structure
Currently.. you can make a hacky function to get [id]
But in situations like
in foo.ts things get alot more complicated to get all the query parameters.
making a object in the request object similiar to in serverless functions would be useful
e.g
Describe the solution you'd like
I think having a function like
Is a decent solution. Or maybe using a map will do. But i think you get the point
Describe alternatives you've considered
For non-nested dynamic roots
Beta Was this translation helpful? Give feedback.
All reactions