fix(mobile): resovle redirect issue (#5145)

* fix(mobile): resovle redirect issue

* test: add e2e tests
This commit is contained in:
Zeke Zhang 2024-08-28 14:50:49 +08:00 committed by GitHub
parent 3809108afa
commit fae2205ce1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 4 deletions

View File

@ -0,0 +1,36 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { devices, expect, test } from '@nocobase/test/e2e';
test.use({
...devices['Galaxy S9+'],
});
test.describe('redirect to other page from mobile', () => {
test('redirect to signin page', async ({ page }) => {
const baseURL = process.env.APP_BASE_URL || `http://localhost:${process.env.APP_PORT || 20000}`;
await page.goto('/m/signin');
await page.waitForURL(`${baseURL}/signin`);
expect(page.url()).toBe(`${baseURL}/signin`);
// do not redirect to mobile page
await page.waitForTimeout(5000);
expect(page.url()).toBe(`${baseURL}/signin`);
});
test('redirect to admin page', async ({ page }) => {
const baseURL = process.env.APP_BASE_URL || `http://localhost:${process.env.APP_PORT || 20000}`;
await page.goto('/m/admin/settings/@nocobase/plugin-api-keys');
await page.waitForURL(`${baseURL}/admin/settings/@nocobase/plugin-api-keys`);
expect(page.url()).toBe(`${baseURL}/admin/settings/@nocobase/plugin-api-keys`);
});
});

View File

@ -179,22 +179,26 @@ export class PluginMobileClient extends Plugin {
Component: 'MobileHomePage', Component: 'MobileHomePage',
}); });
// 跳转到主应用的登录页 // redirect to main app signin page
// e.g. /m/signin => /signin
this.mobileRouter.add('signin', { this.mobileRouter.add('signin', {
path: '/signin', path: '/signin',
Component: () => { Component: () => {
window.location.href = window.location.href window.location.href = window.location.href
.replace(this.mobilePath, '') .replace(this.mobilePath + '/', '/')
.replace('redirect=', `redirect=${this.mobilePath}`); .replace('redirect=', `redirect=${this.mobilePath}`);
return null; return null;
}, },
}); });
// 跳转到主应用的页面 // redirect to main app admin page
// e.g. /m/admin/xxx => /admin/xxx
this.mobileRouter.add('admin', { this.mobileRouter.add('admin', {
path: `/admin/*`, path: `/admin/*`,
Component: () => { Component: () => {
window.location.replace(window.location.href.replace(this.mobilePath, '')); if (window.location.pathname.startsWith(this.mobilePath + '/')) {
window.location.replace(window.location.href.replace(this.mobilePath + '/', '/'));
}
return null; return null;
}, },
}); });