inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.3k stars 423 forks source link

Would be great to have query params as props also, like Nextjs #1771

Closed vitalijalbu closed 3 months ago

vitalijalbu commented 8 months ago

Version:

Describe the problem:

Hi guys, I'm coming from nextjs to inertiajs, really a good product and I love it. But there's a route minus. Of course it can be fixed, but would be fine having it as default. Problem: Would be great to have query params as props also, like Nextjs, so we can access it like:

const { id, query, url } = usePage();

This is my current code to create a dynamic navbar, based o nthe id of the url:

const { id, url } = usePage();
console.log('id', usePage())
console.log('url', url)

See more here: https://github.com/inertiajs/inertia/discussions/1768

shengslogar commented 8 months ago

usePage doesn't come with any preloaded data. It spits out whatever you bind to it. What's preventing you from sharing request()->all() in your middleware?

Issues should be saved for actual bug reports.

vitalijalbu commented 8 months ago

Ok thanks, I think documentation is not complete and can be improved… there are a lots of things that many starter devs don’t find on docs website and find replies elsewhere…

craigrileyuk commented 8 months ago

Documentation can't include everything that a dev might think a package should do because they used something vaguely similar and that package did it.

Inertia is simply a bridge between your Laravel controllers and your frontend. It is not designed to be a do-everything framework.

Why not use something like

const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('myParam');

or you could Inertia::share an array that tells your navbar which items to include rather than doing so on the frontend.

derrickreimer commented 3 months ago

Good recommendations here for sharing/accessing params. Closing this issue for now, since this lives in the Ideas discussions: https://github.com/inertiajs/inertia/discussions/1768