ruanyf/react-demos

how to add css file to the component

Lilliansiyin opened this issue · 1 comments

I tried to import the corresponding css file to the LogIn component like this:

import '../css/login.css';
import React from 'react';
const LogIn = React.createClass(.......)

But encountered with this error:

C:\Users\username\Desktop\APPStore>node server.js
module.js:471
    throw err;
    ^
Error: Cannot find module '../css/login.css'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\LIN SIYIN\Desktop\AppStore\APPStore\components\LogIn.js:5:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

How can I solve it? Thanks a lot!

And my other question is how can I reference to another component in the button onClick() event? The reason Why I am trying to do this is because I want to direct to another page when click the button.

Importing CSS needs Webpack. Visit this demo. https://github.com/ruanyf/webpack-demos#demo04-css-loader-source

If you want to redirect to other pages, the easiest way is to reset window.location.

onClick() {
  window.location = 'https://google.com';
}