wouter icon indicating copy to clipboard operation
wouter copied to clipboard

Support passing down state in `memoryLocation`.

Open Grsz opened this issue 1 year ago • 3 comments

Following the testing instructions about passing down memoryLocation(...).hook to Router I couldn't find a way to pass down state to the current location. The only args memoryLocation receives are:

  path?: Path;
  static?: boolean;
  record: boolean;

It would be a very useful feature to let an additional prop be passed: state.

Grsz avatar Oct 26 '24 10:10 Grsz

Hi @Grsz, it sounds like a nice feature to have! Adding a label to put it in a backlog, in the meantime feel free to open a pull-request.

I suppose the hook factory function can return a state object, the only caveat that it can't be destructured e.g.:

const { hook, state, navigate } = memoryLocation(...)

// state === {}
navigate("/", { state: { foo: "bar" } });

// state is still {}, so you have to use this instead
cost location = memoryLocation(...)
location.state //OK!

I think that it absolutely ok as long as we mention it in the docs.

molefrog avatar Nov 04 '24 14:11 molefrog

shouldn't it be availble from useLocation? 🤔

KutnerUri avatar Aug 24 '25 15:08 KutnerUri