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

Calling navigate with navigateOptions not working as expected #262

Closed
rjgamble opened this issue Jan 12, 2021 · 3 comments
Closed

Calling navigate with navigateOptions not working as expected #262

rjgamble opened this issue Jan 12, 2021 · 3 comments

Comments

@rjgamble
Copy link

Hi @krasimir I'm seeing an issue in 8.4.1 where I call router.navigate with navigateOptions but it doesn't appear to be respecting the options I've set. Here is an abbreviated example of my setup:

const router = new Navigo('/');

router.on({
    '/abc-1234': {
        as: 'routeA',
        uses: (match) => { console.log('Should reach here.'); },
        hooks: {
            before: (done, match) => {
                router.navigate('/item/abc-1234', {
                    historyAPIMethod: 'replaceState',
                    updateBrowserURL: true,
                    updateState: true,
                    callHandler: false,
                    force: true
                });

                done();
            }
        }
    }
});

router.on({
    '/item/abc-1234': {
        as: 'routeB',
        uses: (match) => { console.log('Should not reach here because callHandler=false.') }
    }
});

router.resolve();

What I'm expecting from this setup is that when I browse to /abc-1234 it fires the before hook in "routeA", which in turn tells the router to update the browser URL to "/item/abc-1234" and use "replaceState" in the browser history. It should then continue to execute the "routeA" handler and finish.

What I'm actually seeing is that it executes "routeA" correctly but for updating the browser URL. Have I set the navigateOptions correctly?

Additionally, I don't see another entry in browser history so I assume the replaceState method is working correctly but to know for sure, I'd need to see the URL change.

@krasimir
Copy link
Owner

Nice example. I'll spin up a unit test and will get back to you.

krasimir pushed a commit that referenced this issue Jan 12, 2021
@krasimir
Copy link
Owner

It's the force field. It should be false. Here's a unit test that covers this scenario https://github.com/krasimir/navigo/blob/master/src/__tests__/issues.spec.ts#L276-L319

force is useful when you want to set the internal state of the router. If the value is true it basically stops the resolving and updates the internal flags only.

@rjgamble
Copy link
Author

Thank you for the prompt response - I have just tested again, specifying false for the force navigation option and this is now working as expected. 👍🏻

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

2 participants