1

If I type anything in my http://localhost:3000/anything it will do the same as if I type home or / or login, nothing. The page will be blank.

My social.js:

import React, { Component } from 'react';
import { Route, Switch } from 'react-router-dom';

import Home from '../../containers/Pages/Home/Home';
import Login from '../../containers/Pages/Login/Login';

class Social extends Component {
    render () {
        return (
            <div>
                <Switch>
                    <Route path="/home" exact component={Home} />
                    <Route path="/login" exact component={Login} />
                </Switch>
            </div>
        );
    }
}

export default Social;

app.js:

import React, { Component } from 'react';
import { BrowserRouter } from 'react-router-dom';

import Layout from './Layout/Layout'
import Social from './containers/Pages/Social';

class App extends Component {
  render() {
    return (
    <BrowserRouter>
        <div className="App">
        <Layout>
            <Social />
        </Layout>
        </div>
      </BrowserRouter>
    );
  }
}

export default App;

Any ideas what is wrong? Thanks.

----- Edit, I notice when I remove <Layout> ... </Layout> from app.js it works.

my Layout.js:

import React, { Component } from 'react';

import Toolbar from '../components/Navigation/Toolbar/Toolbar';

class Layout extends Component {
    
    render() {
        return (
        <>
            <Toolbar />
        </>
        );
    }
}

export default Layout;

and Toolbar:

import React, { Component } from 'react';

import classes from './Toolbar.module.css';

class toolbar extends Component {
    
    render() {
        return(
        <>
            <header className={classes.Toolbar}>
                toolbar
            </header>
        </>
        );
    }
    
}

export default toolbar;
10
  • Use exact property in the routes. What do you want to achieve? Commented Jan 29, 2021 at 17:33
  • Looks everything correct, I tested your code added my own components in place of Home and Login. May be you have console error while rendering home or any component. Can you check. Commented Jan 29, 2021 at 17:35
  • @BlackMath I'd like to open the /home and /login. but all pages are blank Commented Jan 29, 2021 at 17:36
  • @Pavan the only error I got is src\containers\Pages\Home\Home.js Line 2:8: 'firebase' is defined but never used Commented Jan 29, 2021 at 17:36
  • I also paste my index.js code... Commented Jan 29, 2021 at 17:39

1 Answer 1

1

I think you missing the wrapping element around Toolbar component

    import React, { Component } from 'react';
    
    import Toolbar from '../components/Navigation/Toolbar/Toolbar';
    
    class Layout extends Component {
        
        render() {
            return (
           <div>
                <Toolbar />
            <div>
            );
        }
    }

export default Layout;

same with the Toolbar. should be as follows:

import React, { Component } from 'react';

import classes from './Toolbar.module.css';

class Toolbar extends Component {
    
    render() {
        return(
        <div>
            <header className={classes.Toolbar}>
                toolbar
            </header>
        </div>
        );
    }
    
}

export default Toolbar;
Sign up to request clarification or add additional context in comments.

5 Comments

Same error as before, /home or /login not show. They only will show the content if I remove <Layout> from app.js ;/
try with these changes please
Have you found any luck?
I did the changes but nothing ;/
No bro, strange. But I'll remove the <Layout><Social /></Layout> to <Social /> and do something different... Thanks a lot for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.