H
H
hamster1410952021-12-24 17:55:13
React
hamster141095, 2021-12-24 17:55:13

How to know history.length (stack) in react-router-dom 6?

Good afternoon! Tell me how to implement such a function on react-router-dom v6 ?
After all, the history object is gone in version 6, and I can’t find the ifnu in the dock, how to find the history-stack

export const closeModal = (
  history: H.History<unknown>,
  path: string,
) => {
  // history.length <= 2 ? history.push(`/${path}`) : history.goBack();
};


It is clear that history was replaced with navigate and you can rewrite the right side as navigate(-1), but I need to know the stack history ..
Thank you all!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexandroppolus, 2021-12-24
@Alexandroppolus

Yes, there is no way to know. History refers to a browser tab, not to your application. A person could walk through other sites in this tab, and then download you, then the story will already be long, because it is general.
Once I had to get inside the history, I had to file my own implementation of the History interface, connect it to window.history through events, and stick it in the Router instead of the standard BrowserHistory

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question