Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Issue: currentRoute is blank on page load #26

Closed
fabien opened this issue Jan 22, 2021 · 3 comments
Closed

Issue: currentRoute is blank on page load #26

fabien opened this issue Jan 22, 2021 · 3 comments
Labels
Will be fixed in next release These bugs will be fixed soon

Comments

@fabien
Copy link

fabien commented Jan 22, 2021

Hi, first off, this router looks really promising! Nice work!

While playing around with it in a sandbox, I noticed that currentRoute is never populated on the initial load. It is only set when switching to another page - is this a bug? Please see the console at:

https://codesandbox.io/s/svelte-easyroute-simpliest-demo-forked-2k18c

One more thing, the beforeEach doesn't seem to work properly either, the fullPath is always identical on both from and to.

Another thing that I noticed is that apparently, useCurrentRoute currently doesn't return a plain readable Svelte store. If it did, it would make the boilerplate for each component a bit more compact (using reactive $ code), and you would not have to unsubscribe manually. Any thoughts on this?

@fabien
Copy link
Author

fabien commented Jan 22, 2021

The beforeEach bug seems to have been introduced in the 3.0.1 release. Version 3.0.0 works as expected. However, currentRoute is not actually set on initial load here either.

https://codesandbox.io/s/svelte-easyroute-simpliest-demo-forked-i1ds8

In order to get a working currentRoute on initial load, I think this if statement should be removed, so it will not only run in SSR mode:

https://github.com/easyroute-router/svelte-easyroute/blob/master/lib/RouterOutlet.svelte#L88

@fabien fabien changed the title currentRoute is blank on page load Issue: currentRoute is blank on page load Jan 23, 2021
@lyohaplotinka lyohaplotinka added the Will be fixed in next release These bugs will be fixed soon label Jan 23, 2021
@lyohaplotinka lyohaplotinka mentioned this issue Jan 23, 2021
@lyohaplotinka
Copy link
Collaborator

Hello @fabien!

  • Issue with empty currentRoute object on startup is fixed, however, I decided to declare it deprecated and the documentation now recommends using the useCurrentRoute hook since it can work not only in direct children of RouterOutlet.
  • A bug with navigation hooks has also been fixed. To avoid misunderstandings, I note that in your example, in the hook that displays the paths to the console, the "to" and "from" places are reversed (in the console.log)

As for useCurrentRoute, it is not intended to return a valid Svelte store, as it refers to an Observable implemented internally by easyroute-core. It simply provides access to its value.

However, I like the idea of returning the svelte-repository, and perhaps it will be implemented. But not as part of the work on this issue.

In version 3.0.7, the described errors have been fixed.

@fabien
Copy link
Author

fabien commented Jan 24, 2021

Hi @lyohaplotinka!

I think it makes sense to deprecate the currentRoute altogether, however, it would indeed be nice if useCurrentRoute would be abstracted into a Svelte store eventually.

Thanks for the quick fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Will be fixed in next release These bugs will be fixed soon
Projects
None yet
Development

No branches or pull requests

2 participants