Skip to content

Commit aefb561

Browse files
14 - URL Route Path Constants
1 parent 7cf494a commit aefb561

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

full_stack_python/full_stack_python.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from rxconfig import config
66
from .ui.base import base_page
77

8-
from . import pages
8+
from . import navigation, pages
99

1010
class State(rx.State):
1111
"""The app state."""
@@ -16,7 +16,7 @@ def handle_title_input_change(self, val):
1616

1717
def did_click(self):
1818
print("Hello world did click")
19-
return rx.redirect('/about-us')
19+
return rx.redirect(navigation.routes.ABOUT_US_ROUTE)
2020

2121
def index() -> rx.Component:
2222
# Welcome Page (Index)
@@ -30,7 +30,7 @@ def index() -> rx.Component:
3030
# rx.button("About us", on_click=State.did_click),
3131
rx.link(
3232
rx.button("About us"),
33-
href='/about'
33+
href=navigation.routes.ABOUT_US_ROUTE
3434
),
3535
spacing="5",
3636
justify="center",
@@ -46,5 +46,7 @@ def index() -> rx.Component:
4646

4747
app = rx.App()
4848
app.add_page(index)
49-
app.add_page(pages.about_page, route='/about')
50-
app.add_page(pages.pricing_page, route='/pricing')
49+
app.add_page(pages.about_page,
50+
route=navigation.routes.ABOUT_US_ROUTE)
51+
app.add_page(pages.pricing_page,
52+
route=navigation.routes.PRICING_ROUTE)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import routes
2+
3+
__all__ = [
4+
'routes'
5+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
HOME_ROUTE="/"
2+
ABOUT_US_ROUTE="/about"
3+
CONTACT_US_ROUTE="/contact"
4+
PRICING_ROUTE="/pricing"

full_stack_python/ui/nav.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import reflex as rx
22

3+
from .. import navigation
4+
35
def navbar_link(text: str, url: str) -> rx.Component:
46
return rx.link(
57
rx.text(text, size="4", weight="medium"), href=url
@@ -18,21 +20,21 @@ def navbar() -> rx.Component:
1820
height="auto",
1921
border_radius="25%",
2022
),
21-
href='/'
23+
href=navigation.routes.HOME_ROUTE
2224
),
2325
rx.link(
2426
rx.heading(
2527
"Reflex", size="7", weight="bold"
2628
),
27-
href='/'
29+
href=navigation.routes.HOME_ROUTE
2830
),
2931
align_items="center",
3032
),
3133
rx.hstack(
32-
navbar_link("Home", "/"),
33-
navbar_link("About", "/about"),
34-
navbar_link("Pricing", "/pricing"),
35-
navbar_link("Contact", "/contact"),
34+
navbar_link("Home", navigation.routes.HOME_ROUTE),
35+
navbar_link("About", navigation.routes.ABOUT_US_ROUTE),
36+
navbar_link("Pricing", navigation.routes.PRICING_ROUTE),
37+
navbar_link("Contact", navigation.routes.CONTACT_US_ROUTE),
3638
spacing="5",
3739
),
3840
rx.hstack(

0 commit comments

Comments
 (0)