default route resolver (Angular)

Discussão em 'Angular' iniciado por MageWind, Dezembro 13, 2024.

  1. MageWind

    MageWind Guest

    I'm trying to set some state in our NgRx Store for specific pages (I'll cause these POI - "page of interest"). If not one of those pages, I would like to set the Store to a default value. We have many pages, so I would prefer to have a default route resolver for the root page and have the specialized route resolver for the child POIs. Is this possible?

    The problem I'm running into is switching from a POI to a non-POI page should revert the state back to the default.

    const ROOT_PATH = 'root';
    const PAGE_PATH = `${ROOT_PATH}/page`;

    function valueFromStore(): boolean {
    return getFromPage(Store).selectSignal(myValueSelector)();
    }

    describe('PermissionsResolver', () => {
    beforeEach(() => {
    bootstrapPageTest({
    routes: [
    {
    path: ROOT_PATH,
    component: PageComponent,
    resolve: {
    'my_resolver': defaultResolver, // sets the store value to false
    },
    children: [
    {
    path: 'page',
    component: PageComponent,
    resolve: {
    'my_resolver': overrideResolver, // sets the store value to true
    },
    },
    ],
    },
    ],
    // omitted extra stuff
    });
    });

    // This test fails
    it('sets the store to false when switching to an unsupported page', () => {
    verifiedNavigate(PAGE_PATH);
    expect(valueFromStore()).toBeTrue();

    verifiedNavigate(ROOT_PATH);
    expect(valueFromStore()).toBeFalse();
    });
    });

    Continue reading...

Compartilhe esta Página