在Angular 8中,构建生产路由时如果遇到问题,可以尝试以下解决方法:
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'about', component: AboutComponent },
// 其他路由配置...
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
@NgModule({
// ...
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy }
]
})
export class AppModule { }
# Rewrite all requests to the index.html
# Needed for Angular routing to work
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
以上是一些常见的解决方法,可以根据具体情况进行尝试。如果问题仍然存在,可以提供更多的代码和错误信息,以便更好地帮助解决问题。