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

Dynamic Angular Router, change state params on same route #29891

Open
radvansky-tomas opened this Issue Apr 14, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@radvansky-tomas
Copy link

radvansky-tomas commented Apr 14, 2019

Hi everyone, I tried to follow docs and example, but I have no idea how to reload same route with different params, if you have idea what route you are in.

Described here:
https://stackoverflow.com/questions/55644532/how-to-change-route-state-params-for-current-route-using-router-service

But basically lets say that your convention is

/page/:appId/other-parts-of-url/:otherids/etc

And you want to change appId from some global scope. So you can this.router to access current Angular Router instance, and you want to call .navigate() method and load same route but with different appId param.

Any idea, how to do such simple thing ? I am not interested in string parsing url techniques or other "hacky" ideas, thx

@radvansky-tomas

This comment has been minimized.

Copy link
Author

radvansky-tomas commented Apr 15, 2019

Hack solution looks like this:

  const url = this.router.routerState.snapshot.url.toLowerCase();
      const regex = /(?<=\/pages\/)([^/]*)/gm;

      if (url.includes('/pages/') && !url.includes('/app-management') && !url.includes('/profile')) {
        //replace appId
        console.log(url.replace(regex, "123"))
      }

If you look at the code you will realise that from URL i cannot really access state params by its name and I have to make hard-coded exceptions etc to change state param.

I am quite sure that has to be a method which can parse current URL with params. Then change param and pass url back to router.

@radvansky-tomas

This comment has been minimized.

Copy link
Author

radvansky-tomas commented Apr 15, 2019

@ngbot ngbot bot added this to the needsTriage milestone Apr 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.