javascript - 未捕获( promise ): SecurityError: Failed to execute 'pushState' on 'History'

标签 javascript angular typescript angular4-router

这些是我的路线:

const routes:Routes =[
  {path:'', component:WelcomeComponent},
  {path:'profile', component: ProfileComponent},
  {path:'addcourse', component: AddcourseComponent},
  {path:'course', component: CourseComponent},
  {path:'editCourse', component: EditCourseComponent},
  {path:'addLectures', component: AddLectureComponent},
  {path:'login', component:LoginComponent},
  {path:'register', component:RegisterComponent},
  // { path: 'newform', canActivate:[AuthGuard], component:NewFomComponent},
  { path: '**', redirectTo:'', pathMatch:'full'}

我的应用程序从欢迎页面开始,当我单击登录时,它会将我带到类(class)页面,单击类(class)后,应用程序应该将我带到类(class)组件​​,但它会重定向到欢迎页面,当我单击登录时,它会重定向到欢迎页面给我这个错误:

ERROR Error: Uncaught (in promise): SecurityError: Failed to execute 'pushState' on 'History': A history state object with URL 'http://%28login%29/' cannot be created in a document with origin 'http://localhost:4200' and URL 'http://localhost:4200/'.
Error: Failed to execute 'pushState' on 'History': A history state object with URL 'http://%28login%29/' cannot be created in a document with origin 'http://localhost:4200' and URL 'http://localhost:4200/'.

我查找过类似的问题,所有这些问题都建议检查基本 href,在我的应用程序中它设置为/所以没有问题。谁能请问我做错了什么吗?

最佳答案

尝试在路线上添加斜杠:

<a mat-list-item routerLink="/profile" routerLinkActive>Profile</a>

关于javascript - 未捕获( promise ): SecurityError: Failed to execute 'pushState' on 'History' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47440654/

相关文章:

javascript - IndexedDB 是否适合在用户类型输入时提供建议

css - 导入的样式未应用于组件

javascript - Angular 2 相册创建

javascript - 从后端动态接收未知文件类型的图像

javascript - 了解一些 Promises 代码和 typescript

javascript - 删除 mouseleave 上的 contenteditable 属性

javascript - Jquery如何清理我自己的上传插件中的formData对象

html - 单击图像时隐藏 div 并显示另一个

node.js - 如何使用 TypeScript 编写的 Node.js 连接到 MongoDB?

javascript - 未捕获的类型错误 : Cannot read property 'props' of undefined in react-redux