Skip to content
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

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

Open
vitalijalbu opened this issue Jan 18, 2024 · 3 comments
Open

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

vitalijalbu opened this issue Jan 18, 2024 · 3 comments
Labels
react Related to the react adapter

Comments

@vitalijalbu
Copy link

Version:

  • @inertiajs/react version: latest

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:
#1768

@vitalijalbu vitalijalbu added the react Related to the react adapter label Jan 18, 2024
@shengslogar
Copy link

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
Copy link
Author

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
Copy link
Contributor

craigrileyuk commented Jan 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
react Related to the react adapter
Projects
None yet
Development

No branches or pull requests

3 participants