mirror of
https://github.com/rio-labs/rio.git
synced 2026-02-12 00:28:32 -06:00
default navbar: Handle case where multiple pages have same url segment
This commit is contained in:
@@ -147,15 +147,12 @@ class DefaultRootComponent(component.Component):
|
||||
)
|
||||
|
||||
# Which page is currently active?
|
||||
# Prepare the URL
|
||||
segments = self.session.active_page_url.parts
|
||||
|
||||
# Special case: Not deep enough
|
||||
if len(segments) <= 1:
|
||||
# This won't match anything because it's not a valid URL segment"
|
||||
current_page_url = "///"
|
||||
else:
|
||||
current_page_url = segments[1]
|
||||
try:
|
||||
active_page = self.session.active_page_instances[0]
|
||||
except IndexError:
|
||||
# Special case: No page is active. Use a value that won't match any
|
||||
# page
|
||||
active_page = None
|
||||
|
||||
# Add navigation
|
||||
#
|
||||
@@ -174,7 +171,7 @@ class DefaultRootComponent(component.Component):
|
||||
pages.add(
|
||||
NavButton(
|
||||
page,
|
||||
is_current=page.url_segment == current_page_url,
|
||||
is_current=page is active_page,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -55,9 +55,10 @@ class Navbar(rio.Component):
|
||||
# Which page is currently active? This will be used to highlight the
|
||||
# correct navigation button.
|
||||
#
|
||||
# `active_page_instances` contains the same `rio.Page` instances
|
||||
# that you've passed the app during creation. Since multiple pages
|
||||
# can be active at a time (e.g. /foo/bar/baz), this is a list.
|
||||
# `active_page_instances` contains `rio.ComponentPage` instances
|
||||
# that that are created during app creation. Since multiple pages
|
||||
# can be active at a time (e.g. /foo/bar/baz), this is a list rather
|
||||
# than just a single page.
|
||||
active_page = self.session.active_page_instances[1]
|
||||
active_page_url_segment = active_page.url_segment
|
||||
except IndexError:
|
||||
|
||||
@@ -27,9 +27,10 @@ class Navbar(rio.Component):
|
||||
# Which page is currently active? This will be used to highlight the
|
||||
# correct navigation button.
|
||||
#
|
||||
# `active_page_instances` contains the same `rio.ComponentPage`
|
||||
# instances that you've passed the app during creation. Since multiple
|
||||
# pages can be active at a time (e.g. /foo/bar/baz), this is a list.
|
||||
# `active_page_instances` contains `rio.ComponentPage` instances that
|
||||
# that are created during app creation. Since multiple pages can be
|
||||
# active at a time (e.g. /foo/bar/baz), this is a list rather than just
|
||||
# a single page.
|
||||
active_page = self.session.active_page_instances[0]
|
||||
active_page_url_segment = active_page.url_segment
|
||||
|
||||
|
||||
Reference in New Issue
Block a user