Skip to content

Commit 24556eb

Browse files
15 - Navigation State
1 parent aefb561 commit 24556eb

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from . import routes
2+
from .state import NavState
3+
24

35
__all__ = [
4-
'routes'
6+
'routes',
7+
'NavState'
58
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import reflex as rx
2+
3+
from . import routes
4+
5+
class NavState(rx.State):
6+
def to_home(self):
7+
return rx.redirect(routes.HOME_ROUTE)
8+
def to_about_us(self):
9+
return rx.redirect(routes.ABOUT_US_ROUTE)
10+
def to_contact(self):
11+
return rx.redirect(routes.CONTACT_US_ROUTE)
12+
def to_pricing(self):
13+
return rx.redirect(routes.PRICING_ROUTE)
14+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from .about import about_page
22
from .pricing import pricing_page
3+
from .contact import contact_page
34

45
__all__ = [
56
'about_page',
7+
'contact_page',
68
'pricing_page'
79
]

full_stack_python/pages/contact.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import reflex as rx
2+
3+
from .. import navigation
4+
from ..ui.base import base_page
5+
6+
@rx.page(route=navigation.routes.CONTACT_US_ROUTE)
7+
def contact_page() -> rx.Component:
8+
my_child = rx.vstack(
9+
rx.heading("Contact Us", size="9"),
10+
rx.text(
11+
"Something cool about us.",
12+
),
13+
spacing="5",
14+
justify="center",
15+
align="center",
16+
min_height="85vh",
17+
id='my-child'
18+
)
19+
return base_page(my_child)

full_stack_python/ui/nav.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ def navbar() -> rx.Component:
7171
rx.icon("menu", size=30)
7272
),
7373
rx.menu.content(
74-
rx.menu.item("Home"),
75-
rx.menu.item("About"),
76-
rx.menu.item("Pricing"),
77-
rx.menu.item("Contact"),
74+
rx.menu.item("Home",
75+
on_click=navigation.NavState.to_home),
76+
rx.menu.item("About",
77+
on_click=navigation.NavState.to_about_us),
78+
rx.menu.item("Pricing",
79+
on_click=navigation.NavState.to_pricing),
80+
rx.menu.item("Contact",
81+
on_click=navigation.NavState.to_contact),
7882
rx.menu.separator(),
7983
rx.menu.item("Log in"),
8084
rx.menu.item("Sign up"),

0 commit comments

Comments
 (0)