J
J
jazzus2019-07-27 10:51:54
Vue.js
jazzus, 2019-07-27 10:51:54

How to work with history.replaceState + axios + vue?

I'm trying to link axios and url for filtering without reloading the page, but with parameters in the url. They suggested doing this using history.replaceState.
I did

fetch() {
    history.replaceState({type_id: this.filter.type_id}, "type_id", url);
    axios.get(url, {
        params: {
            type_id: this.filter.type_id,
        }
    })
}

And yes, the url now displays the parameters website/filter?type_id=10
But if I press enter, it will return the data to the page as json. Well, understandable, because. the request went from the url, not through axios. And what to do? How to live with it now?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2019-07-27
@jazzus

Made a request type check on the back

if ($request->ajax()) {
    return json;
}

now json does not show by link ..
the url that is built in the address bar has changed to be different from the axios request and made history.replaceState after the request so that the url is built according to the current data
. I don’t know if it’s correct or not, but I didn’t find information on how to do it. Please share if anyone has experience.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question