Comments (6)
Hi,
Great question! In React there are multiple ways you can go about doing what you want.
One way we are doing in on of our production application is following this pattern
const Routes = () => (
<Main>
<Switch>
<Route exact path="/" component={HomePage} />
<Route path="/another-sub-page" component={JustAnotherPage} />
<Route path="/about-page" component={About} />
</Switch>
</Main>
);
Now, Main
component is basically a wrapper to our application which is just a header and a footer and whatever inside there will be the children
in this case.
from react-webpack-babel.
Cool!
I've updated the code, but still App
doesn't contain anything, it's just a place in which I put default styles. Is it right?
import React, { Component } from "react";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import Header from "./header";
import Footer from "./footer";
class Main extends Component {
render() {
return (
<div className="Main">
<Header />
{this.props.children}
<Footer />
</div>
);
}
}
class Routes extends Component {
render() {
return (
<Main>
<Route exact path="/" component={Home} />
<Route path="/another-sub-page" component={JustAnotherPage} />
<Route path="/about-page" component={About} />
</Main>
);
}
}
export default Routes;
import React, { Component } from "react";
import "normalize.css";
import "styles/base/_main.sass"; // Global styles
import "styles/base/_common.sass"; // Global styles
import styles from "./app.sass"; // Css-module styles
class App extends Component {
render() {
return (
<div className="App">
Nothing in here...
</div>
);
}
}
export default App;
from react-webpack-babel.
Sorry for the delay, but where do you use App
component right now?
from react-webpack-babel.
I don't... I tried to delete it but it throws a error.
[./src/index.jsx] ./src/index.jsx 2.64 kB {0} [built]
[./src/routes.jsx] ./src/routes.jsx 3.86 kB {0} [built]
+ 573 hidden modules
ERROR in ./src/index.jsx
Module not found: Error: Can't resolve './app' in '/Users/xxx/yyy/zzz/src'
@ ./src/index.jsx 72:2-91:4 73:18-34
@ multi (webpack)-dev-server/client?http://127.0.0.1:8080 webpack/hot/dev-server core-js/fn/promise core-js/es6/object core-js/es6/array react-hot-loader/patch ./src/index.jsx
Child html-webpack-plugin for "index.html":
1 asset
I think it's due to this lines:
// ./index.jsx
// Hot Module Replacement API
if (module.hot) {
module.hot.accept("./app", () => {
const NextApp = require("./app").default;
ReactDOM.render(
<AppContainer>
<Router history={history}>
<NextApp />
</Router>
</AppContainer>,
document.getElementById("app")
);
});
}
Honestly I haven't investigated much as it's already a pretty stiff learning curve understanding React basic steps. I don't even know if my app is making use of it.
Can I just replace ./app
with another file? Maybe ./home
? Not sure what is its purpose.
from react-webpack-babel.
I've just seen @LeonardoGentile has modified those lines 4 days ago in the master repo.
// Webpack Hot Module Replacement API
if (module.hot) {
module.hot.accept('./routes', () => {
renderApp(require('./routes').default);
})
}
I've updated my code accordingly and now I'm able to ditch app.jsx
.
from react-webpack-babel.
BTW the Actually this isn't true. Without knowing it I was mutating the state in my reducer.main
class in the solution I posted above leads to the Block Updating issue. To solve this read this guide.
Wrong. Mutates previous state
object.
// someReducer.js
return { ...newState, ...oldState };
Right. Generates new object.
// someReducer.js
import _ from "lodash";
return _.merge(newState, oldState);
from react-webpack-babel.
Related Issues (20)
- Error after yarn build HOT 8
- when type "npm start" the server does not start HOT 2
- .babelrc module-resolver breaks redux import HOT 5
- Public folder generated after yarn build not working HOT 5
- Update README about how to run for production HOT 1
- Npm dedupe in package-lock.json HOT 1
- Doesn't work on windows
- mobile can't show HOT 2
- Built files don't work when the project is not served from the server root HOT 3
- Error in build process: ERROR in multi ./src/index.jsx ./styles/index.scss HOT 2
- Not able to import fontawesome with standard loading configuration HOT 7
- Not able to render graph component HOT 3
- How to use npm run serve:build and deploy to production HOT 2
- `yarn run build` on our production cannot find SCSS variables HOT 6
- Absolute system paths in js from output bundle HOT 10
- favicon in index.html HOT 4
- SCSS files/syntax not working HOT 9
- Remove jslint HOT 1
- This boilerplate is actually well over 200MB HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-webpack-babel.