Reload SC on route show

It’s been a long day and I’m sure I’m missing something really obvious but I can’t get Server Connect data to refresh each time a route is navigated to. It will load the data on when first viewed but not when navigated away and back again. I know I can attach event handlers such as DMX on click to buttons but many of the places I need it are where buttons are in repeats and the route is assigned dynamically.

I have tried the Route Properties Dynamic Event for show but it doesn’t seem to work:

I should probably add that the SC is placed within the Content page and the ‘No Auto Load’ option is unchecked.

Theoretically (meaning that I have not tried it), you should have the SC on the parent page and there should be a trigger to refresh the data source. That trigger could be the clicking upon the menu item that takes you to the partial.

1 Like

This is one of the caveats of using routes/spa.

Here are the ways in which we handle this:

  1. Keep the sc on route page to be no load using dmx-bind.
    'dmx-bind:noload = broswer1.location.pathname == ‘route1’ ? ‘’ : ‘noload’"
  2. Use some param from url params to be a param of server connect.
  3. Now, when you open the route everytime, noload becomes disabled, but stays active when not on that route. Using param ensures that after redirecting to that route with different param, you server connect automatically reloads.

I hope you understand the logic. :sweat_smile:

1 Like

Thanks @ben,
Unfortunately the buttons are created dynamically so adding an onclick action would also need to be dynamic as the route pages have different SCs on them.
@patrick is there a dmx.parse or equivalent to trigger a flow? All the relevant SC on a route page could then be triggered from a JS function where the flow name would follow a specific pattern. e.g. route /page65/ would have a flow called flow_65 which could be called from something like dmx.parse('flow_'+n+'.load()) where n is a variable for the page number which could be the id of the button

this is great @sid,
I have it working but its not the easiest thing to implement for complex sites. There must be an easier way. I’m going to submit a feature request; please vote if you think it would be useful.

I had to use the browser1.location.pathparts[1] as the pathname element also picked up the parameter so never just matched the route name.

Forgot to give a better solution I had found recently.
Instead of browser, you can also just use name of the route control and its boolean property “isMatch”.
So the condition can be "route_attendperiodsettings_65.isMatch ? … "

Although, looking at you question again, I don’t think you ahould have to do this. The onshown dynamic property does get called everytime we redirect to the route, not just the first time.
Unless, you redirect from the same route, i.e. some button on the route takes you to same route url but with different id. In such a case, using dynamic noload is the way to go.

Another thing the dynamic no load helps with is that when you navigate away, the server action does not get called in with null/empty values. I’m not sure if you have seen this yet, but that was another thing we experienced.

1 Like

Definitely. A native solution would be best.

But given what we have, it is actually quite easy. :sweat_smile:

1 Like

Sure thing. Please share a link here.

1 Like

Thanks for all your help; very much appreciated!

Here’s the feature request:
Feature request

When you say using the onshown event, do you mean the Show dynamic event on the route?
I have tried this:
<div is="dmx-route" path="/65/:c" url="attendperiodsettings.html" id="route_attendperiodsettings_65" exact="true" dmx-on:show=""></div>
It works on first load but if I change route and go back it doesn’t reload.

Ah, ok,
So it appears that the data binding, when using routes, doesn’t correctly add the id for the route.
e.g. If I want to use the dmx-on:show to trigger a flow on a content page you have to manually add in the id for the route:
it generates:
but I needed to change it to
@George, @patrick it appears that maybe the data binding could be improved for routes

Yes, that one.
It should get called every time the app redirects to that route.
In case you are redirecting to the route, form the route, it will not get fired.

For eg: You have a link on homepage, which opens route1. In that case going back and forth between route and home page should always call “show” event.
But, if you have a link on route1, which redirects with some other ID param on route1, “show” event will not get invoked.

This is the behaviour we have seen in our projects upto 3.0.1. I am not sure if this is broken in 3.0.2 or in nodeJS type server.

1 Like

I now see that it does get called and it not adding the route id when using a the picker in the dynamic event had thrown me.

1 Like

So looks like the shown event is fine. :sweat_smile: