'Does Using Query Parameters For Routing/Navigation Have Any Bad Side Effects?
I was tasked with working on navigation for a website that uses PHP, Slim, and Svelte for backend, routing, and UI respectively.
I'm facing a problem now where client-side routing isn't possible because of the fact that Svelte components are mapped to different Slim routes for example:
/store/account/orders
I thought about using query parameters for inter-component routing (i.e. Navigating between component routes) for example:
/store?route=tools/account?route=reset/orders?route=recent
I wanted to know:
- Are there any downsides to this approach?
- Does it in any way cause problems to the user/browser?
- Does it have any security-related issues?
EDIT:
In order to make the question clearer here is an example of what I'm trying to achieve:
Assume I have the following Slim routes:
/home/cart/orders/account
Each of the previous routes points to a different Svelte component and each component should be able to render different things depending on the route's URL for example:
/cartcan have the subroute/cart/checkout. This makes theCartcomponent render the checkout controls instead of the normal cart ones./orderscan have the subroute/orders/recentwhich renders the recent order controls instead of normal ones.- etc...
The problem is I can't achieve this because I can't extract the /orders/[subroute_name] for instance from inside components as they're themselves subroutes.
Solution 1:[1]
The best URLs:
- Adequately describe the content
- Are short enough to be memorable and easily typed
- Don't have to change if the technology powering your site changes
Using query parameters in your URLs works and doesn't introduce huge problems, but it does make them significantly harder for users to understand. The ?route= in the URLs is just there for your tech stack and makes your URL usability worse.
Even simplifying your suggestions to remove route= would be an improvement. /orders?recent is a much better URL than /orders?route=recent
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stephen Ostermiller |
