@deot/helper-route
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

@deot/helper-route

Route

import * as Route from "@deot/helper-route";

// or
import { Route } from "@deot/helper";

merge

Route.merge(route: object, options: object)

基于规则构建新的url

  • route: 路由规则
  • options: 可配置参数

rule: 规则:

  • path: string, string[] 路径
  • query: object 参数

示例

Route.merge({
	// path: '/home',
	path: ['/', 'home'],
	query: { name: 'wya-team' }
});

parse

Route.parse(url: string, options: object)

解析当前路由 -> { query: {}, path: [] }

  • url: 路径,默认值:当前路由
  • options: 可配置参数

示例

Route.parse();

get

Route.get(key: string, url: string, options: object)

设置版本号

  • key: 参数键值
  • url: 路径,默认值:当前路由
  • options: 可配置参数

示例

Route.get('name');

约定

let url = `?a=${encodeURIComponent('&')}`; // '?a=%26'

decodeURIComponent(url); // a=&

encodeURIComponent(url); // '%3Fa%3D%2526'
  • 期望: { a: '&' }
  • 实际: { a: '' }

为了避免该情况,内部对url不直接decodeURIComponent, 仅当对值进行decodeURIComponent. 所以%3Fa%3D%2526是无效的;

merge调用时,value的值会被decodeURIComponent

get('a', '?a=%26'); // &

merge({ query: { a: '&' } }); // ?a=%26

parse('?a=%26'); // query.a === '&' (true)

Readme

Keywords

none

Package Sidebar

Install

npm i @deot/helper-route

Weekly Downloads

8

Version

1.1.3

License

MIT

Unpacked Size

13 kB

Total Files

7

Last publish

Collaborators

  • deot