我試圖從網站運行一個Angular 2應用程序,其中基本url應該是http://www.example.com/app而不是http://www.example.com。我已經嘗試了幾個指南,通過設置基本元素的href(例如:Angular 2 router no base href set)來改變這種情況,但這些都不起作用。我仍然只能訪問根url上的頁面(因此http://www.example.com/something而不是http://www.example.com/app/something)。這是index.html文件目前的樣子:更改Angular2主要網址
<!doctype html>
<html>
<head>
<base href="/app">
<title>Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<!-- Bootstrap stylesheet -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<!-- Bootstrap (and jQuery) scripts -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<!-- Font Awesome icons! -->
<script src="https://use.fontawesome.com/9fbdc2c47e.js"></script>
</head>
<body>
<app-root>
<div class="centered-container">
<!-- Show animated loading icon -->
<div id="loading-notification">
<i class="fa fa-refresh fa-spin fa-5x fa-fw"></i>
</div>
</div>
</app-root>
</body>
</html>
我做了什麼錯了?我在路由器路徑怎麼看起來像一個例子:
RouterModule.forRoot([
{
path: "language",
component: LanguageComponent
},
{
path: "404",
component: NotFoundComponent
},
{
path: "**",
component: NotFoundComponent
}
]),
UPDATE:
我終於定了!在構建生產應用程序時,應使用以下命令:ng build --target=production --base-href /app/ --aot true
。這一切都固定:)
使應該列在app.module.ts裏面的引導標記 – skid