前后端router

修改

前后端router

通过controller生成server端的react-router,并且也生成client端的react-redux的Provider(里面还是封装了react-router)

1
2
3
4
5
6
7
8
@Controller('') 
class FooController {
@Get('/')
@View('index')
index(@Ctx() ctx) {
return '<h1>hello koa-cola !</h1>'
}
}

自动生成的server端的react-router:

1
2
3
<Router ... >
<Route path="/" component={IndexComponent} />
</Router>

通过react-router的match到对应的route后,再通过Provider,最终渲染出html:

1
2
3
<Provider store={store} key="provider">
<SomeReduxComponent />
</Provider>

client端Provider则是:

1
2
3
4
5
<Provider store={store} key="provider">
<Router ... >
<Route path="/" component={IndexComponent} />
</Router>
</Provider>