ReactJs import css still stays in page when route changes reactjs import css,reactjs import component,reactjs import image,reactjs

I am using two main layouts with react router like below. I have written AppRoute component to use different layouts with switch.

Problem is when i come back to "/" home from "/login" or "/register" route some import css related to "LayoutLoginRegister" still stays in browser. So it breaks the page. Because this css belongs to "LayoutLoginRegister" not "LayoutLanding"

App.js

 const AppWrapper = styled.div`
  margin: 0 auto;
  min-height: 100%;
`;

const AppRoute = ({ component: Component, layout: Layout, ...rest }) => (
  <Route
    {...rest}
    render={(props) => (
      <Layout>
        <Component {...props} />
      </Layout>
    )}
  />
);

AppRoute.propTypes = {
  component: React.PropTypes.any.isRequired,
  layout: React.PropTypes.any.isRequired,
};


export default function App() {
  return (
    <AppWrapper>
      <Helmet
        titleTemplate="%s - React.js Boilerplate"
        defaultTitle="React.js Boilerplate"
      >
        <meta name="description" content="A React.js Boilerplate application" />
      </Helmet>
      <Switch>
        <AppRoute exact path="/" layout={LayoutLanding} component={HomePage} />
        <AppRoute path="/features" layout={LayoutLanding} component={FeaturePage} />
        <AppRoute path="/login" layout={LayoutLoginRegister} component={LoginPage} />
        <AppRoute path="/register" layout={LayoutLoginRegister} component={RegisterPage} />
      </Switch>
    </AppWrapper>
  );
}

LayoutLoginRegister Layout

import React from 'react';
import PropTypes from 'prop-types';
import './LayoutLoginRegister.scss';

export class LayoutLoginRegister extends React.Component { // eslint-disable-line react/prefer-stateless-function
  render() {
    return (
      <div>
        {this.props.children}
      </div>
    );
  }
}

LayoutLoginRegister.propTypes = {
  children: PropTypes.object.isRequired,
};

export default LayoutLoginRegister;
Answer:1



  1. reactjs import css
  2. reactjs import component
  3. reactjs import image
  4. reactjs import json file
  5. reactjs import file outside src
  6. reactjs import js file
  7. reactjs import svg
  8. reactjs import as

I have an array of times in state I use to calculate an average time, also in state. this.state = { avgTime: null, allTimes: [] } then the method to do the calculation: this.getTime = () => {...

I have an array of times in state I use to calculate an average time, also in state. this.state = { avgTime: null, allTimes: [] } then the method to do the calculation: this.getTime = () => {...

I want to convert my <button> to a <Link>. But I keep getting an error. Warning: Failed prop type: Invalid prop `to` supplied to `Link`. My code looks like this. import React from '...

I want to convert my <button> to a <Link>. But I keep getting an error. Warning: Failed prop type: Invalid prop `to` supplied to `Link`. My code looks like this. import React from '...