当我尝试在URL中添加新参数时,它会覆盖React Storybook中的该参数。

huangapple go评论89阅读模式
英文:

when i tried to add new parameter in url it override my that parameter in react storybook

问题

我在我的React项目中使用了Storybook npm,我的URL如下:http://localhost:35475/?path=/story/simple-usage--client-demo。当我尝试在URL中添加其他参数,例如:http://localhost:35475/?path=/story/simple-usage--client-demo&test=123 并重新加载页面时,它会删除我的测试参数。有人可以帮助我解决这个问题吗?以下是我添加的代码:

import * as React from 'react';
import { storiesOf, addParameters, addDecorator } from '@storybook/react';
import { setOptions } from '@storybook/addon-options';
import { themes } from '@storybook/theming';
import './demos/helpers/index.css';
import { Toolkit } from '@projectstorm/react-canvas-core';

Toolkit.TESTING = true;

addParameters({
    options: {
        theme: themes.dark,
    }
});

setOptions({
    name: 'STORM React Diagrams',
    url: 'https://github.com/projectstorm/react-diagrams',
    addonPanelInRight: true
});

addDecorator(fn => {
    Toolkit.TESTING_UID = 0;
    return fn();
});

import demo_client from './demos/client-demo-simple';
import demo_simple from './demos/demo-simple';
import demo_flow from './demos/demo-simple-flow';
import demo_performance from './demos/demo-performance';
import demo_locks from './demos/demo-locks';
import demo_grid from './demos/demo-grid';
import demo_listeners from './demos/demo-listeners';
import demo_zoom from './demos/demo-zoom-to-fit';
import demo_labels from './demos/demo-labelled-links';
import demo_dynamic_ports from './demos/demo-dynamic-ports';
import demo_alternative_linking from './demos/demo-alternative-linking';
import demo_custom_delete_keys from './demos/demo-custom_delete_keys';

storiesOf('Simple Usage', module)
    .add('Client Demo', demo_client);

希望这可以帮助您解决问题。

英文:

I have used storybook npm in my react project, I have my url like this http://localhost:35475/?path=/story/simple-usage--client-demo , when i tried to another params in that url like http://localhost:35475/?path=/story/simple-usage--client-demo&test=123 and reoload it then it removed my test params, can anyone please help me to resolve this issue ? here i have added my code for it

import * as React from 'react';
import { storiesOf, addParameters, addDecorator } from '@storybook/react';
import { setOptions } from '@storybook/addon-options';
import { themes } from '@storybook/theming';
import './demos/helpers/index.css';
import { Toolkit } from '@projectstorm/react-canvas-core';

Toolkit.TESTING = true;

addParameters({
	options: {
		theme: themes.dark,
	}
});

setOptions({
	name: 'STORM React Diagrams',
	url: 'https://github.com/projectstorm/react-diagrams',
	addonPanelInRight: true
});

addDecorator(fn => {
	Toolkit.TESTING_UID = 0;
	return fn();
});

import demo_client from './demos/client-demo-simple';
import demo_simple from './demos/demo-simple';
import demo_flow from './demos/demo-simple-flow';
import demo_performance from './demos/demo-performance';
import demo_locks from './demos/demo-locks';
import demo_grid from './demos/demo-grid';
import demo_listeners from './demos/demo-listeners';
import demo_zoom from './demos/demo-zoom-to-fit';
import demo_labels from './demos/demo-labelled-links';
import demo_dynamic_ports from './demos/demo-dynamic-ports';
import demo_alternative_linking from './demos/demo-alternative-linking';
import demo_custom_delete_keys from './demos/demo-custom_delete_keys';

storiesOf('Simple Usage', module)
	.add('Client Demo', demo_client)

答案1

得分: 1

尝试将URL作为编码后的形式传递:

encodeURIComponent('http://localhost:35475/?path=/story/simple-usage--client-demo&test=123')

像这样

"http%3A%2F%2Flocalhost%3A35475%2F%3Fpath%3D%2Fstory%2Fsimple-usage--client-demo%26test%3D123"
英文:

Try passing the url as encoded one

encodeURIComponent('http://localhost:35475/?path=/story/simple-usage--client-demo&test=123')

like this

"http%3A%2F%2Flocalhost%3A35475%2F%3Fpath%3D%2Fstory%2Fsimple-usage--client-demo%26test%3D123"

huangapple
  • 本文由 发表于 2020年1月3日 18:32:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576986.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定