一、angular默認路由 h5路由
將angular項目的 index.html 的標籤修改爲 <base href="/myangular/"> 重新編譯部署
修改ngnix服務器的配置文件nginx.conf
location /myangular {
alias /html/myangular;#angular項目所在目錄
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
二、angular hash路由 #(不需要修改服務器)
直接在angular項目的app.module.ts文件中添加相關配置
方法1:
imports: [
RouterModule.forRoot(routers, {useHash: true})
],
方法2:
//導入hash模塊
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
@NgModule({
//進行配置
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
})