在Angular javascript中更改路由时,css无法加载

时间:2019-05-20 16:07:48

标签: angular

当我更改为“联系”页面等其他路线时,我的应用程序主页可以正常工作,当我回到“主页”路线时,轮播均已损坏。我认为这是JavaScript无法加载的问题。更改路线时如何加载JavaScript?

这就是我将脚本导入index.html的方式

<body>
  <app-root></app-root>
  <script src="../assets/dist/js/jquery-3.3.1.min.js"></script>
  <script src="../assets/dist/js/bootstrap.min.js"></script>
  <script src="../assets/dist/js/modernizr.js"></script>
  <script src="../assets/dist/js/select2.min.js"></script>
  <script src="../assets/dist/js/jquery.menu-aim.js"></script>
  <script src="../assets/dist/js/jquery-ui.js"></script>
  <script src="../assets/dist/js/jquery.nice-select.min.js"></script>
  <script src="../assets/dist/js/owl.carousel.js"></script>
  <script src="../assets/dist/js/jquery.magnific-popup.js"></script>
  <!-- <script src="../assets/dist/js/own-menu.js"></script>  -->
  <script src="../assets/dist/js/jquery.bxslider.min.js"></script>
  <script src="../assets/dist/js/xpedia.js"></script>
</body>

我在app-routing.module.ts中设置路由如下

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { LoginComponent } from './login/login.component';
import { RegisterComponent } from './register/register.component';

import { NewVehiclesComponent } from './new-vehicles/new-vehicles.component';
import { PreOwnedVehiclesComponent } from './pre-owned-vehicles/pre-owned-vehicles.component';
import { AboutUsComponent } from './about-us/about-us.component';
import { ContactComponent } from './contact/contact.component';

const routes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'login', component: LoginComponent },
  { path: 'register', component: RegisterComponent },
  { path: 'new-vehicles', component: NewVehiclesComponent },
  { path: 'pre-owned', component: PreOwnedVehiclesComponent },
  { path: 'about-us', component: AboutUsComponent },
  { path: 'contact', component: ContactComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

0 个答案:

没有答案