NextJS和Firebase Hosting-直接访问动态路线,重定向到生产中的index.js

发布于 2025-01-29 11:07:39 字数 436 浏览 4 评论 0 原文

我没有找到有关此行为的任何文档,但是这里是...

基本上我已经建立了一个index.js页面和一个动态[address] .js页面。

我在这里面对的问题是,每当我访问[地址] .js页面时,以“/helloworld”为端点,当我完全期望[address] .js的内容显示时,我都会重定向到index.js。 。

这只有在部署到Firebase托管后才发生,而不是在Local主机环境中发生的。

作为解决方法,我将此代码段添加到index.js上的使用效率方法中,以路由返回[地址] .js .js .js。这感觉非常效率低下。

const path = router.asPath;

if (
  path &&
  (path !== "/[address]")
) {
  Router.push(`${path}`);
}

I haven't found any documentation on this behavior but here it goes...

Basically I have established an index.js page and a dynamic [address].js page.

Problem I'm facing here is that whenever I visit the [address].js page with something like "/helloworld" as an endpoint, I get redirected to index.js when I fully expected the contents of [address].js to show.

This is only happening after deployment to firebase hosting and not happening in localhost environment.

As a workaround, I added this code snippet to the useEffect method on index.js to route back to [address].js everytime I get redirected to index.js. This feels very inefficient.

const path = router.asPath;

if (
  path &&
  (path !== "/[address]")
) {
  Router.push(`${path}`);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§对你不离不弃 2025-02-05 11:07:39

在这里为问题提供一些清晰和理解。

事实证明,我在动态路由上的问题与NextJS无关,而与Firebase平台上的静态托管站点无关。

这是一篇文章,有助于涵盖对燃料托管中动态路线的担忧:https://medium.com/hackernoon/firebase-to-the-rescue-dynamic-routing-via-hosting-functions-integration-aef888ddf311

Here to provide some clarity and understanding around the problem.

It turns out that my issue with dynamic routing has nothing to do with NextJS and more to do with static hosting of sites on the firebase platform.

Here's an article that helps to cover this concern about dynamic routes on firebase hosting: https://medium.com/hackernoon/firebase-to-the-rescue-dynamic-routing-via-hosting-functions-integration-aef888ddf311

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文