gpt4 book ai didi

Angular1 位置 html5mode 等效于 angular2

转载 作者:太空狗 更新时间:2023-10-29 17:35:06 25 4
gpt4 key购买 nike

我正在尝试找到可以在 angular2 中启用 html5mode 的位置。不幸的是无法从文档或任何地方找到它。我正在使用 gulp 和 browser-sync 来加载我的文件。我看到很多人说要使用 connect-modrewrite 之类的东西

browserSync.instance = browserSync.init({
server: {
baseDir: ['app'],
middleware: [
proxyMiddleware,
modRewrite([
'^[^\\.]*$ /index.html [L]'
])
]
},
});

我设置了它,但它仍然不起作用,除了主 url 之外,我得到 404。有什么线索吗?

最佳答案

您正在寻找的是 PathLocationStrategy 这是默认值 LocationStrategy

注意

使用它时,您需要将服务器设置为将所有 请求重定向到根 URL。例如,如果您的用户请求 myApp.com/someRoute然后 Assets 将从该不正确的网址解析。相反,您希望服务器为 index.html 提供服务页面不管指定的路由如何,但仍然保持路由不变,以便客户端应用程序可以使用它。

另外一定要设置你的 <base path="/" />标记在 HTML 的头部。

关于Angular1 位置 html5mode 等效于 angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35246634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com