Javascript Angular2当我刷新页面时,不是在路由器参数中加载页面

Javascript Angular2当我刷新页面时,不是在路由器参数中加载页面,javascript,angular,typescript,Javascript,Angular,Typescript,我的应用程序在所有路由器中正常加载,但当我使用 应用程序无法加载带有参数的路由器 示例:localhost:3000/usersid/:id 路由器代码为: const appRoutes: Routes = [ { path: 'user', component: UserComponent }, { path: 'info', component: InfoComponent }, { path: 'users', component: UsersComponent }, {

我的应用程序在所有路由器中正常加载,但当我使用 应用程序无法加载带有参数的路由器

示例:
localhost:3000/usersid/:id

路由器代码为:

const appRoutes: Routes = [
  { path: 'user', component: UserComponent },
  { path: 'info', component: InfoComponent },
  { path: 'users', component: UsersComponent },
  { path: 'usersid/:id', component: UsersIdComponent },
  { path: '', component: MainComponent },
  { path: '**', component: MainComponent }
];
以及params路由器的组件

import{Component} from '@angular/core'
import { ActivatedRoute } from '@angular/router';
import * as Datastore from 'nedb';

@Component({
  moduleId : module.id ,
  templateUrl : 'userid.component.html' ,
  styles : [`
    .SamRouter {
        overflow-y: auto;
    }
    `]
})

export class UsersIdComponent {
  id: any;
  private sub: any;
  constructor(private route: ActivatedRoute) {}

  ngOnInit() {
      this.sub = this.route.params.subscribe( params  => {
      // this.id = +params['id']; // (+) converts string 'id' to a number
      this.id = params['id'] || 0 ;

        // In a real app: dispatch action to load the details here.
     });
        console.log(  this.id )
   }
   ngOnDestroy() {
    //  this.sub.unsubscribe();
    }

}
错误消息:

‌​ootstrap.min.js 未能加载资源:服务器以404状态响应 (未找到)加载失败 资源:服务器响应状态为404(未找到)

更改此项:

const appRoutes: Routes = [
  { path: 'user', component: UserComponent },
  { path: 'info', component: InfoComponent },
  { path: 'users', component: UsersComponent },
  { path: 'usersid/:id', component: UsersIdComponent },
  { path: '', component: MainComponent },
  { path: '**', component: MainComponent }
];
对此:(请注意Routes数组中的第四个元素)


这取决于您使用的服务器。 您需要将服务器配置为在路由不存在时转到index.html。
当您按F5键时,服务器将搜索不存在的文件,服务器应返回index.html,然后角路由器将执行其余操作。

您的url显示:localhost:3000/users/:id,但您的配置是path:'usersid/:id'。也许可以检查一下。抱歉像这样:例如:当我在这个链接页面加载它没有问题。。。。。。当点击F5页面无法加载时,我评论说,url实际上是
usersid/:id
:)你能发布你的server.js文件吗
const appRoutes: Routes = [
  { path: 'user', component: UserComponent },
  { path: 'info', component: InfoComponent },
  { path: 'users', component: UsersComponent },
  { path: 'users/:id', component: UsersIdComponent },
  { path: '', component: MainComponent },
  { path: '**', component: MainComponent }
];