question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nuxt, routing without initial query parameters

See original GitHub issue

Bug 🐞 Hey Algolia

We have a solution using algolia and vue instantsearch in nuxt. All the features wors as intended and everything is good. except the routing feature in algolia.

When we load a page using the queries in algolia it has some initial parameters even thoung nothing is set in the filter yet. is there any solution to change the initial url when no filter params is set

from: /alle-produkter/?AHjort%20Products%20da-DK%5BsortBy%5D=AHjort%20Products%20da-DK to: /alle-produkter/

This is the router code:

export function nuxtRouter(vueRouter: any) {
    return {
      read() {
        return vueRouter.currentRoute.query;
      },
      write(routeState: any) {
        vueRouter.push({
          query: routeState
        });
      },
      createURL(routeState: any) {
        return vueRouter.resolve({
          query: routeState
        }).href;
      },
      onUpdate(cb: any) {
        if (typeof window === "undefined") return;

        (this as any)._onPopState = (event: any) => {
          const routeState = event.state;
          if (!routeState) {
            cb(this.read());
          } else {
            cb(routeState);
          }
        };
        window.addEventListener("popstate", (this as any)._onPopState);
      },
      dispose() {
        if (typeof window === "undefined") { return; }

        window.removeEventListener("popstate",  (this as any)._onPopState);
      },
    };
}

And when i use the route back (popstate) i have to go back 3 times to go back the the previous page.

Tell me if you need more from me to go more in depth with this issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:25 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
bootsmann95commented, Oct 1, 2020

Thank you @Haroenv it all works now! THANK YOU!!

1reaction
bootsmann95commented, Sep 30, 2020

@Haroenv i can see its because my price filter is programatically setting som values. so everything works now thanks a lot! do you have any codesandbox with a range slider using vue-slider?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get route url params in a page in Nuxt2 and 3?
To read params from URL you should use this way in Nuxt: this.$route.query.
Read more >
File System Routing - Nuxt
File system routing. Nuxt automatically generates the vue-router configuration based on your file tree of Vue files inside the pages directory.
Read more >
How to Use URL Query Params in Nuxt 3 | by Cody Bontecou
With access to our route, we can check the query variable (what's after the = in streamer= ) using route.query.streamer . Easy! I...
Read more >
Accessing Route Parameters in Nuxt 3 - Server Side Up
Accessing route parameters is an essential for your Nuxt 3 app. Route parameters are the dynamic pieces of your URL that determine what ......
Read more >
Routing - NuxtJS
Validate Route Params ... Nuxt.js lets you define a validator method inside your dynamic route component. ... If the validate method does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found