frontarm / navi

🧭 Declarative, asynchronous routing for React.
https://frontarm.com/navi/
MIT License
2.07k stars 71 forks source link

How to set Context inside a route definition? #179

Closed OnkelTem closed 4 years ago

OnkelTem commented 4 years ago

I wonder how can I set a context variable inside a route definition so that its parent could get this information?

For instance how to set the context.myParam in the following example:

compose(
  withView((request, context) => (
    const param = context.myParam  // <== 
    return (
      <DefaultPageLayout param={param}>
        <View/>
      </DefaultPageLayout>
    )
  ),
  mount({
    "/some-route": route({
      // ??? I take it I can do it here somehow
    })
  })
)
jamesknelson commented 4 years ago

I'd highly discourage this pattern, but that said, if you set an object on the context you should be able to mutate its properties from a child -- just like a React ref object.