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

Using useHash won't route properly #26

Open
weilinzung opened this issue Nov 14, 2021 · 4 comments
Open

Using useHash won't route properly #26

weilinzung opened this issue Nov 14, 2021 · 4 comments

Comments

@weilinzung
Copy link

weilinzung commented Nov 14, 2021

When using useHash on the route, query params would be missing after navigating with the query params.

 RouterModule.forRoot(routes, { useHash: true })

Navigating:
http://localhost:4200/app/#/user?search=test

Then became:

http://localhost:4200/app/#/user

@cztomsik
Copy link

we are using this trick in our app module:

  providers: [
    ...,
    {
      provide: BIND_QUERY_PARAMS_OPTIONS,
      useValue: {
        windowRef: {
          location: {
            get search() {
              return window.location.hash.replace(/[^?]*\??/, '');
            },
          },
        },
      },
    },
   ...
   ]

@weilinzung
Copy link
Author

weilinzung commented Dec 3, 2021

@cztomsik It works on the URL if with strategy: 'modelToUrl'. but that still doesn't patch the params value into the formGroup filed.

  public filterFormGroup = this.fb.group({
    search: [null]
  });

  private bindQueryParamsManager = this.bindQueryParams
    .create<{ search: string }>([
      {
        queryKey: 'search',
        type: 'string',
        strategy: 'modelToUrl'
      }
    ])
    .connect(this.filterFormGroup);

@cztomsik
Copy link

cztomsik commented Dec 3, 2021

we are little behind (2-3 versions), so I can't tell if it still works, but it definitely worked for us

@JannikWempe
Copy link

I can confirm the issue and the suggested fix by @cztomsik didn't work for me either

"@ngneat/bind-query-params": "^5.0.0",
"@angular/core": "~12.2.13",

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

No branches or pull requests

3 participants