要解决Angular 6单独的URL总是路由到主页的问题,您可以使用HashLocationStrategy代替默认的PathLocationStrategy。
在您的app.module.ts文件中,首先导入HashLocationStrategy和LocationStrategy:
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
然后,在@NgModule装饰器的providers数组中,将LocationStrategy设置为HashLocationStrategy:
@NgModule({
  ...
  providers: [
    { provide: LocationStrategy, useClass: HashLocationStrategy }
  ],
  ...
})
export class AppModule { }
这样做将使用hash模式而不是默认的HTML5历史记录API模式来处理路由。
现在,当您在浏览器中导航到单独的URL时,它应该能够正确路由到相应的组件,而不是始终路由到主页。
                    上一篇:Angular 16处理来自Drupal CMS的HTML事件监听器和HTML转换
                
下一篇:Angular 16单元测试与Jasmine->signInWithEmailAndPassword(来自angular/fire/auth)spy工作不正常