Skip to content

useRouteName#9758

Merged
Tobbe merged 9 commits intoredwoodjs:mainfrom
Tobbe:tobbe-use-route-name
Dec 28, 2023
Merged

useRouteName#9758
Tobbe merged 9 commits intoredwoodjs:mainfrom
Tobbe:tobbe-use-route-name

Conversation

@Tobbe
Copy link
Copy Markdown
Contributor

@Tobbe Tobbe commented Dec 26, 2023

Our users wants more introspection possibilities into the router. This PR makes it possible to get the name of the current route.

One possible use case is for analytics.

See also #9755 for a related PR

From the docs:

useRouteName

Use the useRouteName() hook to get the name of the current route (the page
the user is currently visiting). The name can then also be used with routes
if needed to dynamically get the url to the current page:

const routeName = useRouteName()
const routeUrl = routeName ? routes[routeName]() : undefined

Fixes #3787

@Tobbe Tobbe changed the title useRouteName [RFC]: useRouteName Dec 26, 2023
@Tobbe Tobbe added the release:feature This PR introduces a new feature label Dec 26, 2023
@Tobbe Tobbe added this to the next-release milestone Dec 26, 2023
Comment thread docs/docs/router.md Outdated
@Tobbe Tobbe changed the title [RFC]: useRouteName useRouteName Dec 27, 2023
@Tobbe Tobbe enabled auto-merge (squash) December 27, 2023 22:32
@Tobbe Tobbe force-pushed the tobbe-use-route-name branch from a9e5f7a to 569f8ff Compare December 27, 2023 22:43
@Tobbe Tobbe merged commit faec2af into redwoodjs:main Dec 28, 2023
@Tobbe Tobbe deleted the tobbe-use-route-name branch December 28, 2023 13:26
dac09 added a commit to dac09/redwood that referenced this pull request Dec 29, 2023
…od into feat/api-skip-prebuild-try-2

* 'feat/api-skip-prebuild-try-2' of github.com:dac09/redwood:
  chore(ci): retry detectChanges on error (redwoodjs#9769)
  useRouteName (redwoodjs#9758)
  docker.md: Fix web path (redwoodjs#9768)
@jtoar jtoar modified the milestones: next-release, v7.0.0 Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:feature This PR introduces a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: useCurrentRoute or useRouteName

2 participants