DEV Community

Alicia Fasciocco
Alicia Fasciocco

Posted on

Explain React-Router's custom 'history' like I'm five

Declarative routing -- what/when/why? I want to understand!

Top comments (2)

Collapse
 
wolfhoundjesse profile image
Jesse M. Holmes

This isn't ELI5, but in Angular, I used routerReducer to control the router in the store. In React, perhaps that is what is meant by:

The most common use-case for using the low-level is to synchronize a custom history with a state management lib like Redux or Mobx.

So imagine you want to dispatch an action and then navigate to another route in your application. Declarative routing may let you do both at the same time.

Another example might be that you want to change the way a user interacts with an application after visiting a new screen. I've seen this pattern take some heat before, but I remember implementing it once before. I'll see if I can post a relative example.

I haven't visited this in React yet, but now that you've brought it to my attention, I will! Thanks!

Collapse
 
notfocaccia profile image
Alicia Fasciocco

Ah! Thanks, Jesse. "Declarative routing may let you do both at the same time." -- this line, in particular, will stick with me.