in Education by
i'm messing with React and i was trying to make some transition between the router pages. Before using the switch tag, my code was working just fine, but after, the roter wont work and no components get rendered. This is my app.js import React, { Component } from "react"; import { BrowserRouter, Route, Switch } from "react-router-dom"; import { CSSTransition, TransitionGroup } from "react-transition-group"; import "./App.scss"; import "./vendor/bootstrap/bootstrap-reboot.min.css"; import "./vendor/bootstrap/bootstrap-grid.css"; import Content from "./components/Content"; import Header from "./components/Header"; import Skills from "./components/Skills"; import Portfolio from "./components/Portfolio"; import Timeline from "./components/Timeline"; import Footer from "./components/Footer"; import Monitoria from "./components/Monitoria"; import About from "./components/About"; import Contact from "./components/Contact"; class App extends Component { state = { header_infos: [ { job: "Desenvolvedor Web", college: "Faculdade Guararapes - Ciência da Computação 5º Período" } ] }; render() { return (
( ( )} /> )} />
); } } export default App; If needed, this is my navbar class: import React from "react"; import "../sass/Header.scss"; import { NavLink } from "react-router-dom"; const Header = () => { return (

Logo

); }; export default Header; Actually, i dont know if i was doing the router the right way before, because i was using 3 . The reason was that i needed only these 3 components to be loaded in my index, and this was my workaround. Before the modification, i was using only BrowserRouter and Route, no switch and it worked just fine, but without the transition animations. So i tried to follow one tutorial, and it said that i needed to use Switch and now nothing gets rendered and i really dont know why. Thanks, as always. This is the tutorial i followed: https://www.youtube.com/watch?v=NUQkajBdnmQ JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Switch will only render the first Route or Redirect that matches, so only gets rendered, although it seems you're already rendering that before the Switch anyway. ( )} /> None of these components above will render as they're being ignored by the switch. Best bet would be to create a parent component for the things that need to be on the path /, and render that in the first (and only) exact path="/" Route.

Related questions

0 votes
    I'm using an abstract superclass for some React components that share methods and some (but not all) props ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm using an abstract superclass for some React components that share methods and some (but not all) props ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    This is the example table that I want to do From the 'Yellow' highlight (row & column) color. I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    Check out this example code I saw: import * as React from 'react'; const Count: React.FunctionComponent ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I have a React User Profile page that retrieves User object from back-end. User profile object contains a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    What is the difference between hub,switch and router?In tabular form? Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    What is the difference between Hub, Switch, and Router?...
asked Nov 20, 2020 in Education by Editorial Staff
0 votes
    I am using BrowserRouter as Router from react-router-dom. I want to host my application at a path ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I need to take the users input from the select box for Allergen1 once an option is selected and the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Can the users simply switch to a previous version while working on a repository in SVN? If so, what is the simplest method for this according to you?...
asked Feb 18, 2021 in Technology by JackTerrance
0 votes
    I am developing a single-page-application using vue-cli3 and npm. The problem: Populating a basic integer ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am developing a single-page-application using vue-cli3 and npm. The problem: Populating a basic integer ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    Which of them is not an appropriate method of router security? (a) Unused ports should be blocked (b) Unused ... Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 3, 2021 in Education by JackTerrance
0 votes
    Tor (The Onion Router) is not a service or part of the darknet. 1) True 2) False...
asked Dec 30, 2020 in Technology by JackTerrance
...