我已经使用角度实现了路由,如下所示 -
export const routes: RouterConfig = [
{ path: '', component: HomeComponent },
{ path: '**', component: SearchComponent }
];
我需要匹配所有默认网址进行搜索。 Angular 应用程序中有一些静态资源,例如 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 {}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)