angular - 当我运行命令“ng build”时,我无法从浏览器输入路线,只能通过内部导航
问题描述
当我用 编译我的项目时ng build
,它成功完成。
我得到这样的结构:
<!doctype html>
<html lang="es" class="thin scrollbar-gris" style="overflow-x: visible;">
<head>
<meta charset="utf-8">
<title>title</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.51e30e538d2560c1a9e9.css"></head>
<script src="./assets/lib/wow.min.js"></script>
<script>
new WOW().init();
</script>
<body >
<app-root style="overflow-x: visible;"></app-root>
<script type="text/javascript" src="runtime.a5dd35324ddfd942bef1.js"></script><script type="text/javascript" src="polyfills.3eb7881d3a00da6c675e.js"></script><script type="text/javascript" src="scripts.dd86f002a5aef1b13f0f.js"></script><script type="text/javascript" src="main.23ac360bc829b49bc07d.js"></script></body>
</html>
但它没有找到库,然后我改变
<base href="/">
至
<base href="./">
它有效。但真正的问题发生在我的应用程序的路由中,例如这个:
http://localhost/my_folder_compilated/programa/detalle-programa/5cf7d27faa8e180017211754
// this is the route that I have in my app.routing.ts
{path: 'programa/detalle-programa/:programaId', component: DetalleProgramaComponent},
{path: '**', component: NotFoundComponent}
一切正常,但是如果我在这条路线中重新加载页面,我会收到错误 404(未找到页面),如果我按照我的应用程序的链接正常浏览,我没有任何问题。
在编译之前我没有这种问题,我可以从浏览器输入这条路线。
总之:
我执行ng build
,输出是code
我放的。改成href = "/"
,"./"
因为不认了.js files
。我对此进行测试xaamp
(localhost/my_folder_compilated/)
我的应用程序位于根文件夹中,例如在 xaamp 中是 htdocs/my_folder_compilated 并且浏览器中的访问是 localhost/my_folder_compilated
我该怎么做才能纠正它?
解决方案
与 PathLocationStrategy 一起使用的基本 href 的预定义 DI 令牌。基本 href 是在生成和识别 URL 时应保留的 URL 前缀。
在你的app.module.ts
providers: [{provide: APP_BASE_HREF, useValue: '/'}],
推荐阅读
- null - qliksense 表达式中的空条件
- php - 尝试使用 htaccess 删除 .php 扩展名
- c - 循环查找 C 中数组中的最后一个偶数
- laravel - 如何在 Laravel 中将用户输出数据的第一个单词大写?
- reactjs - 网络连接检查反应
- dialogflow-es - Dialogflow Intent 在从 Google Assistant 的列表视图键中单击时不匹配,但在以纯文本形式编写时有效
- amazon-web-services - API Gateway HTTP 客户端请求与 IAM 身份验证与 Go
- ios - 无法使用 CloudKit 获取 sharedCloudDatabase 自定义区域中的记录
- c# - unity 无法使用 kinect V2 录制音频
- node.js - 如何在节点js中从服务返回两个以上的值到控制器