我想知道是否有一种方法可以重定向路由或返回Response带有数据的 a 并使用该函数在另一个页面上获取它loader。
基本上,我试图使用表单创建一个新对象,并重定向到另一个我想要显示创建成功消息的页面。
这是一个表单页面示例:
我正在尝试在正文中发送消息Response。
import { ActionFunction, Form } from "remix";
export const action: ActionFunction = async ({ request }) => {
// const formData = await request.formData();
return new Response(JSON.stringify({ message: "Hello world!" }), {
status: 303,
headers: {
Location: "/new-page",
},
});
};
export default function Index() {
return (
<div>
<Form method="post">
<input type="text" id="name" name="name" />
<button type="submit">Submit</button>
</Form>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
此时NewPage我需要知道是否有办法获取重定向响应上的消息。
import { ActionFunction …Run Code Online (Sandbox Code Playgroud) 我一直在尝试模拟 getter 函数,但该函数也被另一个计算属性调用,并且它作为未定义函数返回。
这是一个面包屑组件,会根据路由路径而变化。第一个测试正常通过,因为该组件不应该渲染。但第二个测试尝试使用用户名通过 getter 获取用户数据。
我的疑问是关于模拟吸气剂。它不是应该返回 beforeEach 定义的模拟对象吗?
提前致谢!
这是测试规范:
import {
shallowMount,
createLocalVue
} from '@vue/test-utils'
import Breadcrumb from '@/components/Breadcrumb.vue'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(VueRouter)
const router = new VueRouter()
describe('Breadcrumb.vue', () => {
let store
beforeEach(() => {
store = new Vuex.Store({
getters: {
getUserByUsername: (path) => ({
name: {
first: 'FirstName',
last: 'LastName'
}
})
}
})
})
it('renders home page breadcrumb', () => {
const wrapper …Run Code Online (Sandbox Code Playgroud)