我正在尝试使用' create-react-app'在React上锻炼项目。我在同一个项目中使用Bootstrap。除了“Bootstrap Grid”之外,它似乎工作得很好。 正如您在快照中看到的那样,该项目似乎选择了自定义Bootstrap字体&但是,它无法加载和拾取Bootstrap Grid布局。
我正在使用' create-react-app'这个项目。 以下是我的文件..
package.json ..
{
"name": "demo-react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"loaders.css": "^0.1.2",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-loaders": "^2.6.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-scripts": "^1.0.14",
"react-select": "^1.0.0-rc.10",
"react-slick": "^0.15.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
index.html ..
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Demo React App</title>
<!-- jQuery for Bootstrap -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
index.js ..
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
app.js ..
import React, { Component } from 'react';
// import logo from './logo.svg';
import './App.css';
import getRoutes from './routes.js';
import Header from './components/Header/Header.js';
import Footer from './components/Footer/Footer.js';
class App extends Component {
render() {
let RouterComponent = (
<div>
{getRoutes()}
</div>
);
return (
// <div className="App">
// <header className="App-header">
// <img src={logo} className="App-logo" alt="logo" />
// <h1 className="App-title">Demo React App</h1>
// </header>
// <p className="App-intro">
// To get started, edit <code>src/App.js</code> and save to reload.
// </p>
// </div>
<div className="container-fluid">
<Header />
<div className="row">
<div className="col-md-offset-1 col-md-10 col-sm-offset-1 col-sm-10 col-xs-offset-1 col-xs-10">
<button className='btn btn-default'>Press Me</button>
{RouterComponent}
</div>
</div>
<Footer />
</div>
);
}
}
export default App;
routes.js ..
import React from 'react';
import MainPage from './views/MainPage/MainPage.js';
import RandomPage from './views/RandomPage/RandomPage.js';
import ContactUsPage from './views/ContactUsPage/ContactUsPage.js';
import { HashRouter,Route } from 'react-router-dom';
export default function getRoutes() {
return (
<HashRouter>
<div>
<Route exact path='/' component={MainPage}></Route>
<Route exact path='/RandomPage' component={RandomPage}></Route>
<Route exact path='/ContactUsPage' component={ContactUsPage}></Route>
</div>
</HashRouter>
);
}
我知道有一种替代方法可以使用&#39; React Bootstrap&#39;但是,我很想知道为什么Twitter Bootstrap本身没有与这个项目很好地集成。 感谢。
PS:此外,控制台上没有错误或警告。