Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angular – 在进行硬刷新时,路由对我不起作用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在看这个源代码https://github.com/angular/angular.io/blob/master/public/docs/_examples/toh-5/dart/lib/app_component.dart

而且当我转到根目录时,我的应用程序似乎正在路由.

本地主机:8080 /

当我在我的应用程序中移动时路由更新,但似乎如果我在某个地方:localhost:8080 /基板中的仪表板,并进行硬刷新,它会失败.它会给我404未找到!错误.

如果我这样做它会工作:localhost:8080 /#!/ dashboard但这不是传递给我的应用程序的地址.

在index.html我有:< base href =“/”>

我的App_Component.dart文件如下:

import 'package:angular2/angular2.dart';
import 'package:angular2/router.dart';

import 'hero_component.dart';
import 'heroes_component.dart';
import 'dashboard_component.dart';
import 'hero_service.dart';
@Component(
    SELEctor: "my-app",directives: const [ROUTER_DIRECTIVES],providers: const [Heroservice,ROUTER_PROVIDERS],templateUrl: "app_component.html")
@RouteConfig(const [
  const Route(
      path: "/dashboard",name: "Dashboard",component: DashboardComponent,useAsDefault: truE),const Route(
      path: "/detail/:id",name: "HeroDetail",component: HeroDetailComponent),const Route(path: "/heroes",name: "Heroes",component: HeroesComponent)
])
class AppComponent {
  String title = "Tour of Heroes";
}

似乎我有路由工作除了这个以外的一切.

我想要的最终状态是:localhost:8080 / detail / 14,它会打开正确的组件.这是现在在新网站引用上完成的事情,就像在整个应用程序中导航一样.

解决方法

要切换到HashLOCATIOnStrategy,请将提供程序更改为

bootstrap(AppComponent,[
  Heroservice,ROUTER_PROVIDERS,provide(LOCATIOnStrategy,useClass: HashLOCATIOnStrategy)
])

如果您想使用PathLOCATIOnStrategy,您可以使用此pub-wrapper https://pub.dartlang.org/packages/pub_serve_rewrites,它允许将PathLOCATIOnStrategy与pub serve一起使用.

对于部署,您需要配置您在那里使用的Web服务器以支持HTML5 pushState.

大佬总结

以上是大佬教程为你收集整理的angular – 在进行硬刷新时,路由对我不起作用全部内容,希望文章能够帮你解决angular – 在进行硬刷新时,路由对我不起作用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。