浏览代码

fix(core): fallback to index.html on asset loading, closes #2020 #2021 (#2022)

Lucas Fernandes Nogueira 4 年之前
父节点
当前提交
8a7921e5cb
共有 2 个文件被更改,包括 10 次插入0 次删除
  1. 5 0
      .changes/fix-asset-loading-vue-router.md
  2. 5 0
      core/tauri/src/manager.rs

+ 5 - 0
.changes/fix-asset-loading-vue-router.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Fallback to `index.html` on asset loading so router with history mode works.

+ 5 - 0
core/tauri/src/manager.rs

@@ -427,6 +427,11 @@ impl<P: Params> WindowManager<P> {
 
         let asset_response = assets
           .get(&path)
+          .or_else(|| {
+            #[cfg(debug_assertions)]
+            eprintln!("Asset `{}` not found; fallback to index.html", path); // TODO log::error!
+            assets.get("index.html")
+          })
           .ok_or(crate::Error::AssetNotFound(path))
           .map(Cow::into_owned);
         match asset_response {