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

ui-router do not propagate my resolve to the component #51

Closed
wilsonsergio2500 opened this issue May 23, 2017 · 5 comments
Closed

ui-router do not propagate my resolve to the component #51

wilsonsergio2500 opened this issue May 23, 2017 · 5 comments

Comments

@wilsonsergio2500
Copy link

wilsonsergio2500 commented May 23, 2017

I am pretty fresh in ui-router with react, I have a very simple example with two components. Top an Bottom

`
const Home = { name: 'top', component: () => (), url: '/' };
const Page1 = {
name: 'top.page1',
component: () => (),
resolve: [{
token: 'page1',
resolveFn: () => RootService()
}]

};
export const Routes: IStateRoute[] = [
Home,
Page1
]`

I am using axios for my http in RootService, so it simply returns axios.get('url')
then injecting my routes simply as

<UIRouter states={Routes} plugins={plugins}> <UIView/> </UIRouter>
The http fires and I can see it in my network in my web tools, if i place a loading component it even awaits for it until it resolves. nonetheless, the value of the resolve is not present in the props.resolves of the Page1 component.

I have red the documentation a couple of times and It does not seem I am missing anything.
Could you let me know what I might be doing odd?

@wilsonsergio2500
Copy link
Author

wilsonsergio2500 commented May 23, 2017

fyi, I am actually returning a component for the top is a <Top/>
component and Page one <FirstPage/>

@elboman
Copy link
Member

elboman commented May 24, 2017

From your code it looks like the page1 state is a child of the top state, make sure there's a UIView that can render the nested one, otherwise it won't render anything.

I created a small webpackbin (https://www.webpackbin.com/bins/-Kktv-C_NIb0Ptsl_wSO) and everything works normally. Do you think you can reproduce the error/problem so I can take a better look? I don't have enough info right now.

@wilsonsergio2500
Copy link
Author

Thank you very much Marco..
All I needed it seems was..
component: (props: any) => (<FirstPage {...props}></FirstPage>),

@elboman
Copy link
Member

elboman commented May 24, 2017

Oh, I think I understand now.

By doing component: (props: any) => (<FirstPage {...props}></FirstPage>) you are actually creating an inline stateless component that renders the FirstPage one:

() => <something /> // <- this is a stateless component

The router injects the props to the component you declare in the state definition, that's the stateless component and not FirstPage.

To fix this you should declare the state like this:

component: FirstPage,

This way you avoid creating the wrapper component.

@wilsonsergio2500
Copy link
Author

ohhh awesome, I get it now. Thank you 👍

@elboman elboman closed this as completed May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants