且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法获取-使用Ionic刷新后出现错误

更新时间:2023-12-03 15:29:40

您遇到的问题是,您没有将所有可能的网址都路由到同一 index.html

The problem you are having is that you do not route all possible urls to the same index.html

当您第一次加载页面(例如,URL为 http://example.com/)时,您的Web服务器将从以下位置提供静态文件 index.html :你的根.更改路线时,您的URL最终为(例如) http://example.com/some_page .这是可行的,因为URL是伪造的",服务器上没有这样的文件.刷新(或直接转到该URL)时,该URL是从服务器请求的,但失败(因为和以前一样,该文件/文件夹不存在).

When you first load the page, say, the URL being http://example.com/, your web server will serve the static file index.html from your root. When changing the route, your URL ends up as (for example) http://example.com/some_page. This works because the URL is "faked", there is no such file on the server. When refreshing (or going to that URL directly), that URL is requested from the server, which fails (since, as before, that file/folder does not exist).

您需要做的是将所有请求(API和whatnot除外)路由到相同的静态 index.html ,这是所有单页应用程序的标准行为:路由是在客户端完成的.

What you need to do is route all requests (excluding API and whatnot) to the same static index.html, this is standard behavior of all single-page apps: The routing is done clientside.