veliovgroup / flow-router

🚦 Carefully extended flow-router for Meteor
https://packosphere.com/ostrio/flow-router-extra
BSD 3-Clause "New" or "Revised" License
202 stars 29 forks source link

Autoscroll Functionality #9

Closed ajschmaltz closed 6 years ago

ajschmaltz commented 7 years ago

For some reason https://github.com/okgrow/router-autoscroll doesn't work with this package. Any suggestions on how to revive this functionality?

dr-dimitru commented 7 years ago

Hello @ajschmaltz ,

A quick look on router-autoscroll repository reveals it's being deprecated:

[DEPRECATED] Smart management of scroll position across route changes for iron and flow router

And it has dependency of original FR package.

But the good news are here - you can implement it easily:

import { FlowRouter } from 'meteor/ostrio:flow-router-extra';

const scrollToTop = () => {
  setTimeout(() => {
    if (!window.location.hash) {
      window.scroll(0, 0);
    }
  }, 25);
};

FlowRouter.triggers.enter([scrollToTop]);

Let me know if it works for you.

dr-dimitru commented 7 years ago

@ajschmaltz did you got a chance to implement it?

tmpg commented 7 years ago

Can this be built into the package? I can't seem to get this to work. Does it go on each route?

dr-dimitru commented 7 years ago

@tmpg

Does it go on each route?

Yes, FlowRouter.triggers registers global trigger and applied to each registered route.

I can't seem to get this to work.

Do you got any errors? Can you add .log to see if it's triggered

Can this be built into the package?

Looks overwhelming to me, as it can be done with few lines in a global trigger. Let's see if it will get up votes by community.

coagmano commented 7 years ago

Looking at okgrow/router-autoscroll, it should work perfectly fine. Just follow the instructions here for compatibility with packages that rely on the original FlowRouter

Even if you don't want to use the package, it's not hard to add to your project with a single global trigger. So I don't see any reason it should be part of the package

dr-dimitru commented 7 years ago

@coagmano well, autoscroll package has dependency of original FlowRouter. Having two packages won't harm your app, but wouldn't be good either. May cause conflicts and increase application size.

coagmano commented 7 years ago

It's a weak dependency, so it won't install automatically. By setting Package['kadira:flow-router'] = Package['ostrio:flow-router-extra']; before it loads, it will use this FlowRouter instead of the original

dr-dimitru commented 7 years ago

@coagmano you right, haven't noticed {weak: true}, my bad. Anyways, this is just 8 lines:

const scrollToTop = () => {
  setTimeout(() => {
    if (!window.location.hash) {
      window.scroll(0, 0);
    }
  }, 25);
};

FlowRouter.triggers.enter([scrollToTop]);
dr-dimitru commented 6 years ago

Shall we move it to the docs and close the ticket? @ajschmaltz @coagmano @mksh-su @tmpg

dr-dimitru commented 6 years ago

Added to docs