Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useRouteName #9758

Merged
merged 9 commits into from
Dec 28, 2023
Merged

useRouteName #9758

merged 9 commits into from
Dec 28, 2023

Conversation

Tobbe
Copy link
Member

@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
docs/docs/router.md Outdated Show resolved Hide resolved
@Tobbe Tobbe changed the title [RFC]: useRouteName useRouteName Dec 27, 2023
@Tobbe Tobbe enabled auto-merge (squash) December 27, 2023 22:32
@Tobbe Tobbe merged commit faec2af into redwoodjs:main Dec 28, 2023
53 of 59 checks passed
@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