dmc.NavLink callbacks

Hi there,

Hope you’re all well.

Is it possibly to find out which dmc.Navlink is triggered with a callback using a pattern matching or ctx.triggeredid in a multi-page app?

I’ve created a multplepage app using one of the appshell templates. In the main app.py and page1.py when I try to trigger a callback on the navlink nclicks, It returns none even when clicked?

If I use ctx.triggeredid In page1, it returns dcc.store object which is a bit odd, but I’m guessing it’s because the appshell navbar and links are In the main app.py?

This code works below works:

# Callback (using the dcc.location provided by Dash Pages)
@app.callback(Output({"type": "navlink", "index": ALL}, "active"), Input("_pages_location", "pathname"))
def update_navlinks(pathname):
    return [control["id"]["index"] == pathname for control in callback_context.outputs_list]

But would like to get the specific navlink id to trigger a callback in one of the subpages.

On a seperate note; is it a bad idea or practice to have one page that generates two different contents based on which linked is clicked?

  • Page x: with href ‘/fruit’, page name=‘apple’, seperate navlink in navbar
  • Page x: with href ‘/fruit’, page name=‘pear’, seperate navlinkim navbar

Or should I wrap a layout in a function and call that instead. For this option can / should the callbacks be inc. in the function?

Thanks for the help!!!