question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update routesMap dynamically

See original GitHub issue

I was recently working on a webapp for work and started messing around with per-client routing (it’s a private webapp, SEO is not of concern). I currently have it implemented with slugs /:client/:thing but that was only after I tried wrapping the redux-first-router reducer to allow injecting new routes into the routesMap on the fly.

I was a bit disappointed to find that when I changed the routesMap in the redux store that change was not reflected by the middleware / enhancer. I had a brief poke through the code and it seems that this is due to the routesmap being passed into the enhancer when connectRoutes is called. I would assume it is possible for the enhancer to read the routesMap from the store instead.

So I suppose I am wondering if there would be any large issues if this was implemented. To my understanding it would change nothing in terms of the API (unless it had to be specifically enabled in the connectRoutes options). Certainly not a high priority feature but it would be nice to be able to define more solid routes for each client.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
faceyspaceycommented, Aug 3, 2017

Comin in a week or so. U gotta make the middleware respond to an action containing the new routes. As well as the reducer which also maintains a reference to it (but that is more standard).

It also may be possible to just update the reducer state and always read from state rather than closure. In a few places that might not be possible, but hopefully that’s not the case.

5reactions
faceyspaceycommented, Aug 15, 2017

ok, this is done. it’s in the @next dist-tag on NPM. get it like this:

yarn upgrade redux-first-router@next

here’s how you use it:

import { addRoutes } from 'redux-first-router'
import universal from 'react-universal-component'

const UniversalComponent = universal(props => import(`./${props.page}`), {
   onLoad: module => {
       const aThunk = addRoutes(module.newRoutes)
       store.dispatch(aThunk)
   } 
})

this is just an example using Universal. you can use any code splitting component/tools you want.

So essentially you have an action creator now to dispatch new routes received via code-splitting.

There’s one thing I’m noticing now that I’m using it with React Universal Component–onLoad doesn’t receive props, so a global store variable had to be imported and used, which is no good. I’ll have to add a 2nd props arg there so your redux connected component can pass dispatch. It should be:

onLoad: => (module, props) => props.dispatch(addRoutes(module.newRoutes))

I’ll make that tweak in RUC.

For now if you’re looking at this and interested, find a way to access store directly or if you’re using other code splitting tools, you know what to do.

Otherwise, i’m closing this issue. feel free to open any specific new Issues. Feel free to add some docs about this. 🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Routing Route Maps | TNSR Documentation
To view route maps, use the show route dynamic route-map [name] command. Add the name of a route map to restrict the output...
Read more >
Dynamically Update a Map - Stack Overflow
I have a bit of a situation. I was assigned a task to create a system that will take a KML file and...
Read more >
Configure Route-Maps Applied with Redistribution Command
This document describes how to configure route-maps that are applied with the redistribute command of dynamic routing protocols.
Read more >
Angular 10: how to create/update routes programmatically
We store the route in a place our routing component/module can read from (here in the window for example); We launch angular application....
Read more >
How to dynamically update or add locations to Google Maps ...
Easy - kinda. Open or create a map. A map can have up to 10,000 lines, shapes, or places. Click Add marker ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found