import { Subject } from 'rxjs/Subject';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { pluck, share, shareReplay, tap } from 'rxjs/operators';
// simulate url change with subject
const routeEnd = new Subject<{data: any, url: string}>();
// grab url and share with subscribers
const lastUrl = routeEnd.pipe(
tap(_ => console.log('executed')),
// defaults to all values so we set it to just keep and replay last one
// requires initial subscription
const initialSubscriber = lastUrl.subscribe(console.log);
// logged: 'executed', 'my-path'
routeEnd.next({data: {}, url: 'my-path'});
const lateSubscriber = lastUrl.subscribe(console.log);