![]() ![]() ![]() User event -> state change -> re-render ✅ Again, the reason for this is because it aligns exactly with the principles of React itself. Instead of using an imperative API ( history.push), we're using a declarative Redirect component. So in our example, let's navigate the user to /dashboard once they've registered for our app.Īfter reading that, there's at least a small chance that you hate it. The typical use case for routing programmatically is routing on some sort of user event that isn't a Link click. Let's look at an example then we'll walk through more of why this isn't as crazy as it may first appear. The primary way you programmatically navigate using React Router v5 is by using a component. The reason I'm emphasizing this is because your initial reaction to what's coming next will most likely be negative. Because React Router's vision is aligned with React's, programmatically navigating with React Router should, by definition, align with those three core concepts. If you broke React down into three core principles, you'd get component composition, declarative UI, and state management - specifically, user event -> state change -> re-render. Fundamentally, what this means is that the same mental model that applies to React should also apply to React Router. The whole goal of the redesign to React Router v3 to v4 was to align React Router's vision with React's. ![]() What I love about React Router is its dedication to declarative, "React like" code. Check your versionThis post assumes you're using React Router v5. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |