Add idx to router.object #34980
tatethurston
started this conversation in
Ideas
Replies: 1 comment 6 replies
-
+1 |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the feature you'd like to request
I'd like to propose adding idx to the router.object.
idx
is included in the history state on every new history entry.This is valuable for reporting purposes such as the number of page views in the current session.
It's also valuable when building native-like applications using nextjs, particularly for back button behaviors. When replicating a native like experience, it's helpful to be able to check if a programatic
router.back()
would kick the user out of the app, and if so, fallback to another page (like a Homepage). This pattern frequently comes up for back buttons rendered on an error page and settings pages.Describe the solution you'd like
A new
idx
field (or perhapspageCount
/pageIndex
?) added to the router object.Describe alternatives you've considered
Accessing
history.state.idx
directly. This works, but is undocumented and I'm concerned about the field changing or being removed in a next update and application code silently breaking.Another option would be to include a
fallback
option with router.back so that users aren't backed out of the application.Beta Was this translation helpful? Give feedback.
All reactions