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

usage in effects / ofRoute operator #69

Open
fxck opened this issue Dec 23, 2020 · 3 comments
Open

usage in effects / ofRoute operator #69

fxck opened this issue Dec 23, 2020 · 3 comments

Comments

@fxck
Copy link

fxck commented Dec 23, 2020

Would something like this be a bad idea? And is there some built-in function that would be able to check if route matches pattern (I imagine link active has to be doing something like that).

private action$ = createEffect(() => this._router.url$.pipe(
  // url is /products/detail/123
  filter((url) => ofRoute('/products/detail/:id', url)),
  tap(console.log)
);
@brandonroberts
Copy link
Collaborator

There isn't a built in function that does this for the entire route, as each segment is parsed at each level in the component hierarchy. Maybe if the effect was tied to the component?

The ofRoute() would match as soon as the location changes, but would potentially happen before the component is rendered. If you're keeping things reactive if should be fine though.

@fxck
Copy link
Author

fxck commented Dec 24, 2020

The ofRoute() would match as soon as the location changes, but would potentially happen before the component is rendered. If you're keeping things reactive if should be fine though.

yea that would be fine in this case, you visit product/123 and you want to check if 123 data already exists and dispatch load action otherwise, I could always dispatch the action from the page component, but I'd rather leave it to the effect

@meeroslav
Copy link
Collaborator

With implementation of custom route matched (currently in PR) this would be possible even with the service, but you would have to manually run the checks that components do.

As Brandon said, it's best to use components. We didn't implement public route change events yet.

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