You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to be able to add links only on some routes (or route groups), and remove them when I go to other routes, but there is no easy way to check if the link has been added, or to remove only a single tag. Flow Router also lacks the necessary hooks to make this smooth.
With Flow you can do it in triggersEnter but if you are navigating between pages that rely on bootstrap (for example) you'll get a flash of unstyled content between routes.
It would be nicer if there was a registry or some way to check if the tag has already been added. I propose the following:
Add a method to remove links based on a globally unique field, such as href/src.
Add a method to check if links are added based on a globally unique field such as href/src.
Have the add methods return a handle that can be passed to a remove method, or that contains methods to manage the lifecyle of the link.
In case anyone is interested, I ended up creating a kind of watcher function in triggers.enter, which detects when the group changes (using a local state var), and adds or removes the link as necessary.
Using this pattern, each managing chunk of code (my main front end, and the flow-db-admin package) can control only their own bits, and I don't have to worry about removing everything all the time.
varcurrentGroup=''FlowRouter.triggers.enter([functiononEnterTrigger(context){// did the group change?if(!context.route.group||currentGroup!==context.route.group.name){constclientLink={rel: 'stylesheet',type: 'text/css',href: '/stylesheets/main.css'}currentGroup=context.route.group&&context.route.group.name// my client routes either use no group (undefined), or 'admin'if(currentGroup==='admin'||!currentGroup){DocHead.addLink(clientLink)}else{DocHead.removeLink(clientLink)// may also clean up Blaze/React remnants here}}}])
My fork of flow-db-admin does something similar for bootstrap and its own links.
I'd like to be able to add links only on some routes (or route groups), and remove them when I go to other routes, but there is no easy way to check if the link has been added, or to remove only a single tag. Flow Router also lacks the necessary hooks to make this smooth.
With Flow you can do it in
triggersEnter
but if you are navigating between pages that rely on bootstrap (for example) you'll get a flash of unstyled content between routes.It would be nicer if there was a registry or some way to check if the tag has already been added. I propose the following:
These methods would also help with issue #34
I'm happy to make a PR for these.
The text was updated successfully, but these errors were encountered: