Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add css file to the component #35

Closed
Lilliansiyin opened this issue Apr 11, 2017 · 1 comment
Closed

how to add css file to the component #35

Lilliansiyin opened this issue Apr 11, 2017 · 1 comment

Comments

@Lilliansiyin
Copy link

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.

@ruanyf
Copy link
Owner

ruanyf commented Apr 11, 2017

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';
}

@ruanyf ruanyf closed this as completed Apr 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants