refactor /:route param
This commit is contained in:
parent
89fc14bb43
commit
4a422af3d6
2 changed files with 12 additions and 10 deletions
|
|
@ -169,16 +169,10 @@ export function parseDeepLink(deepLinkUrl: string): DeepLinkWithData {
|
|||
return {type: DeepLink.Permalink, url: deepLinkUrl, data: {serverUrl, teamName, postId}};
|
||||
}
|
||||
|
||||
const pluginMatch = match<{serverUrl: string; id: string; route?: string[]}>(`:serverUrl(.*)/plugins/:id(${PLUGIN_ID_PATH_PATTERN})/:route+`)(url);
|
||||
const pluginMatch = match<{serverUrl: string; id: string; route?: string}>(`:serverUrl(.*)/plugins/:id(${PLUGIN_ID_PATH_PATTERN})/:route(.*)?`)(url);
|
||||
if (pluginMatch) {
|
||||
const {params: {serverUrl, id, route}} = pluginMatch;
|
||||
const data: DeepLinkWithData['data'] = {serverUrl, teamName: '', id};
|
||||
|
||||
if (route) {
|
||||
data.route = route.join('/');
|
||||
}
|
||||
|
||||
return {type: DeepLink.Plugin, url: deepLinkUrl, data};
|
||||
return {type: DeepLink.Plugin, url: deepLinkUrl, data: {serverUrl, teamName: '', id, route}};
|
||||
}
|
||||
} catch (err) {
|
||||
// do nothing just return invalid deeplink
|
||||
|
|
|
|||
|
|
@ -456,13 +456,21 @@ describe('UrlUtils', () => {
|
|||
expected: null,
|
||||
},
|
||||
{
|
||||
name: 'should not match plugin path without a route',
|
||||
name: 'should match plugin path without a route',
|
||||
input: {
|
||||
url: DEEPLINK_URL_ROOT + '/subpath/deepsubpath/plugins/abc',
|
||||
serverURL: SERVER_WITH_SUBPATH,
|
||||
siteURL: SERVER_WITH_SUBPATH,
|
||||
},
|
||||
expected: null,
|
||||
expected: {
|
||||
data: {
|
||||
id: 'abc',
|
||||
route: undefined,
|
||||
serverUrl: URL_PATH_NO_PROTOCOL,
|
||||
teamName: '',
|
||||
},
|
||||
type: DeepLinkType.Plugin,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue