Azure App Service静态网站route.json不起作用 [英] Azure App Service Static Website routes.json doesn't work

本文介绍了Azure App Service静态网站route.json不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 routes.json 将静态网站(React应用程序)部署到Azure App Service,以启用HTML5路由回退.我的路线json位于/public中,可在URL https://mywebsite.azurewebsites.net/routes.json 下找到.

  {路线":[{"route":"/*","serve":"/index.html","statusCode":200}]} 

重定向无效.我在做什么错了?

解决方案

最新

我认为您混淆了 Web App Static Web App 这两个服务. routes.json 文件仅在

根据React文档,执行以下命令以创建my-app项目.

  1. npx create-react-app my-app
  2. cd my-app
  3. npm run start

然后在公用文件夹中创建 index2.html .

在github中创建一个名为 reacttest 的新存储库.

在my-app目录中,打开cmd并执行以下命令以将代码上传到github.

  1. git init
  2. git add.
  3. git commit -m'init'
  4. git remote add origin https://github.com/yourname/reacttest.git
  5. git push -u原始主机

按照官方文档创建 Azure Static Web Apps Preview .在github中的 Action 中检查发布状态.发布后,您可以看到默认页面.

这时,直接在github的公共文件夹中添加 routes.json 文件.在操作中继续检查发布状态.发布完成后,您可以看到该路由已生效.

访问默认首页时,我们可以看到 index2.html 的内容.

如果要查看 index.html ,我们可以在URL中添加/index.html .

I deployed my static website (React app) to Azure App Service with routes.json to enable HTML5 routing fallback. My routes json is located in /public and is available under URL https://mywebsite.azurewebsites.net/routes.json.

{
  "routes": [
    {
      "route": "/*",
      "serve": "/index.html",
      "statusCode": 200
    }
  ]
}

The redirect doesn't work. What am I doing wrong?

解决方案

Newest

I think you confuse the two services Web App and Static Web App. The routes.json file only takes effect in Static Web App.

According to the React documentation, execute the following command to create the my-app project.

  1. npx create-react-app my-app
  2. cd my-app
  3. npm run start

Then create index2.html in the public folder.

Create a new repository in github with the name reacttest.

In the my-app directory, open cmd and execute the following command to upload the code to github.

  1. git init
  2. git add.
  3. git commit -m'init'
  4. git remote add origin https://github.com/yourname/reacttest.git
  5. git push -u origin master

Follow the official documentation to create Azure Static Web Apps Preview. Check the release status in Action in github. You can see the default page after publishing.

At this time, directly add the routes.json file in the public folder in github. Continue to check the publishing status in Action. After the publishing is completed, you can see that the route is in effect.

When we visit the default homepage, we can see the content of index2.html.

If want see index.html, we can add /index.html in url.

这篇关于Azure App Service静态网站route.json不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆