Router.Navigate from Angular Library Doesn't Work

25 Views Asked by At

I have an Angular workspace where I build and compile 5 packages. I then install those packages on a separate project. When referencing these builds within the same workspace. This works no problem. However, after I pack and publish and install on a new project it no longer works.

I have narrowed the code down to this try catch. No errors are throw, no navigation is performed.

This code is in my component inside my library.

try {
            await this._oidcService.handleCallback();
            const url = sessionStorage.getItem('redirectUrl') ?? '';
            sessionStorage.removeItem('redirectUrl');

            this._router.navigate([url]).then(success => {
                console.log("Navigation successful:", success)
            }).catch(error => {
                console.error("Navigation Error: ", error);
            });
        } catch (error) {
            console.error('Error handling sign-in callback:', error);

            // Handle errors, e.g., show a message, log out, navigate to an error page, etc
            this._router.navigate(['/error'], { queryParams: { error: 'Sign-in callback error' } })
        }

Neither Navigation Successful or the Navigation Error gets triggered. But I can see the session storage is updating and removing the redirect url.

I have attempted to add "preserveSymlinks": true with no difference.

I have logged the Navigation Start/End/Error/Cancel. Nothing indicating that the router is trying to change.

The strangest part is that it works within my library workspace. I have a sandbox application set up to use the dist folder.

Is anyone able to assist me on this matter? Is this even a feature that is allowed, router navigating from a library?

0

There are 0 best solutions below