angular2部署到tomcat中,让他跑起来

  1. 首先使用构建命令(npm run build或ng build)打包,打包完成后项目中会出现一个dist的目录,这个目录就是我们最终要部署的包了,把它命名为cc-client(关于打包后的base路径修改,参考后面的备 注)就可以了。
  2. 将命名好的cc-client整个目录复制到tomcat的webapps目录下。
  3. 运行tomcat,在浏览器中输入http://localhost:8080/cc-client/#/login
  4. 注:想将默认的cc-client修改成你自己的base路径,打开package.json,修改构建命令”build”: “ng build –base-href /你的应用名称/”,例如”build”: “ng build –base-href /demo/”,这里的base路径要和你的项目名称一样。
  5. 如果你的路由方式使用的不是hash方式,那么你刷新后会报404,解决的方式是把路由改成hash方式,例如:export const appRoutes=RouterModule.forRoot(routes,{preloadingStrategy: SelectivePreloadingStrategy,useHash:true});

作者:rotating_windmill

来源:https://blog.csdn.net/rotating_windmill/article/details/76768793


如果给你带来帮助,欢迎微信或支付宝扫一扫,赞一下。