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

getCurrentRoutes api in v4? #2978

Closed
ghost opened this issue Mar 31, 2018 · 6 comments
Closed

getCurrentRoutes api in v4? #2978

ghost opened this issue Mar 31, 2018 · 6 comments

Comments

@ghost
Copy link

ghost commented Mar 31, 2018

how can i get all route in current route stack in v4? i find some talk about Actions.currentRouter, but i cannot find about currentRouter code in v4 source code.

@asciifaceman
Copy link
Contributor

asciifaceman commented Mar 31, 2018

Ah crap I thought I had a code example for this, digging around still...

Can you try setting up a reducer:

const reducerCreate = params => {
  const defaultReducer = new Reducer(params);
  return (state, action) => {
    console.log('ACTION:', action);
    return defaultReducer(state, action);
  };
};

Attach it like so:

      <Router
        ...
        createReducer={reducerCreate}
      >

Now you can console.log(state) in the function and move around its tree, I think what you are looking for is in there IIRC

Looking through the source it doesn't look like currentRouter exists anymore (there IS a currentScene), I'd be curious what you need it for to maybe guide you to an alternate solution?

@ghost
Copy link
Author

ghost commented Apr 1, 2018

i use react native's own navigator now(version 0.39), it has a api called getcurrentroutes, this can get a list include all pushed routes, and i cannot found a similar api in rnrf.

@fatfatson
Copy link

Actions.state

@aksonov
Copy link
Owner

aksonov commented Jun 6, 2018

@fatfatson is correct.

@aksonov aksonov closed this as completed Jun 6, 2018
@matteocollina
Copy link

But Can i get the Stack size?

@daviscabral
Copy link
Collaborator

@matteocollina have you looked at the state object as pointed above? you can get the idea of the stack size by that.

This is a sample that I got by running the tests from the project:

{
  "key": "StackRouterRoot",
  "isTransitioning": false,
  "index": 0,
  "routes": [
    {
      "key": "id-1537858201424-3",
      "isTransitioning": true,
      "index": 1,
      "routes": [
        {
          "params": {
            "init": true,
            "param": "1"
          },
          "routeName": "a",
          "key": "id-1537858201424-2"
        },
        {
          "params": {
            "error": "",
            "param": "2",
            "init": true,
            "data": "abcde",
            "routeName": "c"
          },
          "routeName": "c",
          "key": "id-1537858201424-4"
        }
      ],
      "params": {
        "init": true
      },
      "routeName": "b"
    }
  ]
}

Repository owner locked as resolved and limited conversation to collaborators Sep 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants