我使用angular实现了路由,如下所示 -
export const routes: RouterConfig = [
{ path: '', component: HomeComponent },
{ path: '**', component: SearchComponent }
];
Run Code Online (Sandbox Code Playgroud)
我需要匹配所有默认网址进行搜索.在角度应用程序中有一些静态资源,如js,css文件.我的问题是所有的静态资源现在都要搜索组件.有什么方法可以从路由中排除这些静态资源.
尝试这样的事情。请注意,您需要在顶部导入所有其他模块,并且我假设您正在 app.module.ts 文件中设置路由。
这也使用 Angular1.x 样式的http://url/#/路由样式,因为我发现部署时在浏览器中更加稳定。
我还建议在部署目录的根目录中创建一个静态资产目录并在其中存储静态文件。像这样的东西:
/static/
/css/
/js/
/images/
import all modules...
import { RouterModule, Routes, PreloadAllModules } from '@angular/router';
const routes: Routes = [
{ path: '',
component: HomeComponent,
pathMatch: 'full'
},
{ path: '**',
component: SearchComponent
}
];
@NgModule({
declarations: [
HomeComponent,
SearchComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(routes,
{
useHash: true,
preloadingStrategy: PreloadAllModules
}),
],
bootstrap: [AppComponent]
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3923 次 |
| 最近记录: |