简体   繁体   English

如何在 SVELTE 中使用 page.js 并在编辑时保留动态路由内容

[英]How to use page.js with SVELTE and retain dynamic route content while editing

I am using page.js with SVELTE and it works.我将 page.js 与 SVELTE 一起使用,它可以工作。

The problem:问题:

My app lets users store data via a form and the data is stored in indexedDB (I am using Dexie.js to talk to IndexedDB).我的应用程序允许用户通过表单存储数据,数据存储在 indexedDB 中(我正在使用 Dexie.js 与 IndexedDB 对话)。 The stored data is used to create dynamic routes.存储的数据用于创建动态路线。

Example:例子:

A user submits data called "client" and data is stored in indexedDB as:用户提交称为“客户端”的数据,数据存储在 indexedDB 中:

clients = [{name:"Stackoverflow", id:0}, {name:"Google", id:1}] 

I then create dynamic routes (using page.js) that look like this:然后,我创建如下所示的动态路由(使用 page.js):

http://localhost:5000/client/0/dashboard

The problem is as follows,问题如下,

When I go to a dynamic route and edit components that make up the page (even CSS) upon saving my work, the entire app refreshes.当我在保存我的工作时将 go 转到动态路由并编辑构成页面的组件(甚至是 CSS)时,整个应用程序都会刷新。 In order to get back to my dynamic route I can't just type the URL - I have to go back to the landing page, find the link of the submitted item, click it and be redirected to the desired page.为了回到我的动态路线,我不能只输入 URL - 我必须 go 回到登录页面,找到提交项目的链接,单击它并重定向到所需的页面。

Is there a way to make this easier so that I can edit without that happening?有没有办法让这更容易,这样我就可以在不发生这种情况的情况下进行编辑? The landing page and other static pages do not have this problem.登陆页面和其他 static 页面没有这个问题。

Not sure if this helps but did you add the --single switch to the end of the call to sirv in the package.json 's start script?不确定这是否有帮助,但您是否将--single开关添加到sirvstart脚本中对package.json的调用末尾?

so your package json should contain something like所以你的 package json 应该包含类似


  "scripts": {
    "build": "rollup -c",
    "dev": "rollup -c -w",
    "start": "sirv public --single"
  },

(only the line starting with "start" is relevant. The crucial bit is --single ). (只有以"start"的行是相关的。关键是--single )。

Also the declaration of your route for page.js should be something like /client/:id/dashboard . page.js 的路由声明也应该类似于/client/:id/dashboard

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM