Any help / turorials on how the router works in this specific kit?
See original GitHub issueIt seems to be that the router in this project isn’t configured the same standard way all the tutorials and documentation out there do.
e.g. server.js uses a dispatch event, I can’t find any sample code elsewhere that uses this method, even in the API docs for react-router.
server.get('*', async (req, res, next) => {
...
await Router.dispatch({ path: req.path, context }, (state, component) => {
data.body = ReactDOM.renderToString(component);
data.css = css.join('');
});
const html = ReactDOM.renderToStaticMarkup(<Html {...data} />);
res.status(statusCode).send('<!doctype html>\n' + html);
...
});
I’m trying to configure the router to load routes lazily in a similar way to this example project.
In that huge-apps example code you can asynchonouly chose which routes to load in a route config
module.exports = {
path: 'course/:courseId',
getChildRoutes(location, cb) {
require.ensure([], (require) => {
cb(null, [
require('./routes/Announcements'),
require('./routes/Assignments'),
require('./routes/Grades')
])
})
},
...
}
I can’t figure out how to apply the same thing to the way routing is done in this starter kit, anyone got similar experiences or can share their knowledge?
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
Issue Analytics
- State:
- Created 8 years ago
- Comments:24 (2 by maintainers)
Top Results From Across the Web
What is a Router? How do Routers work? - InetDaemon.Com
This network certification tutorial on routers focuses on identifying network routers, and explaining the functions of routers provide. This ...
Read more >How to Setup and Configure your Home Router
In this tutorial I will explain the various ports available on most routers, and how to set up your router and change common...
Read more >How to Build a Raspberry Pi Router - Step by Step Tutorial
When you use other firmware for a router, it often comes with a fixed set of capabilities. On the other hand, OpenWRT provides...
Read more >How to Set Up a Wireless Network From Start to Finish
Setting up a Wireless Router or fast WiFi Network in your home is ... of how a wireless network works that will help...
Read more >About Routers: Types of Routers, Routing Table and IP Routing
As the name is self-explanatory, routers acquire their nomenclature from the work they perform, means they do routing of data packets from ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
EDIT: Make sure you install the latest version of
react-router
withnpm install react-router@latest
, I thinknpm install react-router
will instead install version 0.13.x.I did do, I’ll try and summarise and strip down my files so you can make use of them. There’s three main files I had to change, app.js, server.js and routes.js. You’ll probably have to edit them a bit to get them to work, but the jist of it is there (bare in mind this is a work in progress).
routes.js
I heavily stripped out the server.js and app.js just to get something working for now, might still be some dead code in there.
With the new server.js file you won’t be able to use the decorators
@withContext
and@withStyles
, this is because it requires a post back to update the css which defeats a lot of the benefits ofreact-router
. For my solution I converted all css to inline styles as pointed out here, you may find a different way to do it. If you need to do media queries a good alternative is to use the@withViewport
decorator that already exists, then in your render method checkthis.props.viewport.width
. See here for more info on server routing.server.js
I’m using a jwt token for my user authentication so I like having this readily available in the context. To do this I had to extend the react-router
RoutingContext
class and add it in. You can skip this if you don’t want a context and just use the defaultRoutingContext
class in your server.js file instead. Open to suggestions on other ways to handle this.AuthRoutingContext.js
For the app.js I actually used the same method as the server.js, even though the documentation encourages you not to however I couldn’t find a way using the normal method to include my
jwt
token in the context. EDIT: Don’t do this client side, I have a feeling this is why my links don’t work.app.js
Open to ideas if anyone’s got better ways of handling stuff.
I see no reason why keep this open 😃