router icon indicating copy to clipboard operation
router copied to clipboard

usage in effects / ofRoute operator

Open fxck opened this issue 5 years ago • 3 comments

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)
);

fxck avatar Dec 23 '20 22:12 fxck

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.

brandonroberts avatar Dec 24 '20 01:12 brandonroberts

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

fxck avatar Dec 24 '20 11:12 fxck

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.

meeroslav avatar Dec 24 '20 11:12 meeroslav