-
Notifications
You must be signed in to change notification settings - Fork 650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL path and query parameters #1714
Comments
Correct, whatever you’re using for HTTP listeners in Node.js would provide these. The specifics vary by framework so the list could be infinite, but here are the 3 most common:
(Vanilla Node is only as common as it is because However, for each case you’ll need to put the import Koa from 'koa'
import markoTemplate from "./whatever.marko"
const app = new Koa()
app.use(ctx => {
ctx.type = 'text/html;charset=utf-8'
ctx.body = markoTemplate.stream({
$global: {
query: ctx.query,
posted: ctx.req.body
}
})
}) <section>
<h2><code>GET</code> parameters</h2>
<pre>${JSON.stringify(out.global.query, null, 2)}</pre>
</section>
<section>
<h2><code>POST</code> parameters</h2>
<pre>${JSON.stringify(out.global.posted, null, 2)}</pre>
</section> |
Ok, thanks for the info, I'll give it a try. It would be nice to support this kind of thing out of the box. Maybe like sveltekit does it: https://kit.svelte.dev/docs#routing-advanced-rest-parameters |
I think it is important to distinguish the difference between the core framework from the prebuilt template. Ie.. the difference between Svelte vs SvelteKit. @tigt's answer is the general one. In a similar way if you were to use Svelte directly there would be no specific solution for routing as it does not come built-in in Svelte. However, It's worth mentioning if you are using Marko CLI, the templates that use Marko Build/Serve, with its built-in file-based routing, that you can get the path params on |
@ryansolid had a quick glance through that project, I think that's what I'm looking for. Once I have a chance to try it out, I'll report back. |
Thanks for the help! @ryansolid that's exactly what I was looking for. Found those docs here: https://github.com/marko-js/cli/blob/main/packages/serve/README.md#route-params for anyone else looking. It doesn't have an example with the BTW, can't get over how fast all of this stuff is, both compiling and rendering 🤯 |
@tigt how do you get around this? I copied your code exactly:
|
I personally use the |
I'm struggling to get anything working, seems like the docs are out of date or something for server integrations at least. I'm on Node 16, maybe that has something to do with it. The only thing that has worked for me is the Marko CLI, it's the only thing that's worked out of the box. If the CLI way of doing things could run some code to preload data before rendering, then add it to inputs, I think I'd have everything I need. |
The Marko CLI should add |
I went back to the code to recall what the issue was and made a new issue here: #1722 |
Any reason This is what I"m getting:
|
@treeder params are handled explicitly by the router and so it makes sense to provided the (already parsed) result to the user. With params there are various formats people use in the wild, especially around nesting. Luckily it seems node is moving toward the web standard way of parsing the querystring which will work nicely here also. Basically you can do: $ const query = new URLSearchParams(input.query);
$ const amount = query.get("amount"); (see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) |
I must be missing something, but I can't seem to find how to get URL and query parameters.
For example, if I have a URL like `/stuff/123?id=456
How do I set that up so that it would use the
stuff
page and then how could I get the path parameter and the query parameter? Or does that require using a server integration?The text was updated successfully, but these errors were encountered: