Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop a query in a url?

I have the following url: http://0.0.0.0:3000/book/all?my_query How to drop "all?my_query" and leave just "book/" I tried to do something like this: if (this.$route.params.item === 'all') { this.$router.replace ('/') }

but it just returns to the main page

like image 402
StockholmSyndrom Avatar asked Mar 02 '18 09:03

StockholmSyndrom


People also ask

How do you give a URL a query?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.

How do you separate a query string from a URL?

The query string is composed of a series of field-value pairs. Within each pair, the field name and value are separated by an equals sign, " = ". The series of pairs is separated by the ampersand, " & " (or semicolon, " ; " for URLs embedded in HTML and not generated by a <form>...

What is the query part of a URL?

A query string is the portion of a URL where data is passed to a web application and/or back-end database. The reason we need query strings is that the HTTP protocol is stateless by design. For a website to be anything more than a brochure, you need to maintain state (store data).

Can I pass URL as query parameter?

Yes, that's what you should be doing. encodeURIComponent is the correct way to encode a text value for putting in part of a query string. but when it is decoded at the server, the parameters of url are interpreted as seperate parameters and not as part of the single url parameter.


1 Answers

To remove all params:

this.$router.replace({'query': null});

To add my_query param:

this.$router.replace({'query': {'my_query': 1}});
like image 137
ndpu Avatar answered Oct 13 '22 23:10

ndpu