[英]Spring Boot + React
我正在嘗試實現非常簡單的CRUD應用程序,它將是一個只有幾個Rest Controller的單頁應用程序。
我在實現過程中遇到的問題是,即使我用React JS編寫的腳本是使用webpack成功構建的,並注入到靜態頁面“ index.html”中,也不顯示內容。
內容正確顯示的情況:
如果不是:
這是我的HomeController,負責映射到“ /”下的靜態頁面
@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String welcome() {
return "index";
}
}
這是我的index.html頁面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content=""/>
<meta name="author" content=""/>
<title>React</title>
<!-- Bootstrap Core CSS -->
<link
href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.6/
cerulean/bootstrap.min.css" rel="stylesheet"/>
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet"
type="text/css"/>
<link href="http://fonts.googleapis.com/css?
family=Source+Sans+Pro:300,400,700,300italic,400italic,700italic"
rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="react"></div>
<script src="../static/built/bundle.js"></script>
</body>
</html>
可能最后有用的最后一件事是app.js :
import React from "react";
import ReactDOM from "react-dom";
import { Router, Route, IndexRoute, hashHistory } from "react-router";
import Archives from "./pages/Archives";
import Featured from "./pages/Featured";
import Layout from "./pages/Layout";
import Settings from "./pages/Settings";
const app = document.getElementById('react');
ReactDOM.render(
<Router history={hashHistory}>
<Route path="/" component={Layout}>
<IndexRoute component={Featured}/>
<Route path="archives(/:article)" name="archives" component={Archives}/>
<Route path="settings" name="settings" component={Settings}/>
</Route>
</Router>,
app);
首先,我想這可能是在路由器和控制器中使用相同URL的問題,但更改它們后仍無法解決問題。 所以我沒有任何想法。
使用Spring Boot提供的默認值時, bundle.js
在bundle.js
的路徑中包含/static/
。
在index.html
將腳本標簽更新為:
<script src="/built/bundle.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.