Skip to content

fix(layout): normalize URL pathname and construction#1788

Closed
chilingling wants to merge 1 commit intoopentiny:developfrom
chilingling:fix/redirectUrl
Closed

fix(layout): normalize URL pathname and construction#1788
chilingling wants to merge 1 commit intoopentiny:developfrom
chilingling:fix/redirectUrl

Conversation

@chilingling
Copy link
Copy Markdown
Member

@chilingling chilingling commented Mar 19, 2026

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

【问题描述】What is the current behavior?

当前如果没有正确的应用 id,会自动跳转到应用中心。
如果用户输入随机的路经,然后在应用中心中跳转应用,新增的 path 不会消失。
比如:

  1. 用户输入了 https://opentiny.github.io/tiny-engine/xxxx,由于没有正确的应用id,会默认跳转到应用中心。
  2. 此时用户选择应用进入应用编辑。随机输入的 xxxx 却没有消失。跟随带入了应用的 path。

Issue Number: N/A

【优化方案】What is the new behavior?

  • URL 路径归一化:在页面加载时,自动将当前 URL 的 pathname 替换为从环境配置中获取的 BASE_URL。
  • 防止残留:有效移除了用户手动输入或其他逻辑可能残留的随机路径。
  • 租户切换逻辑优化:通过 new URL API 基于 basePath 构建租户切换链接,确保路径一致性。
  • URL 初始化逻辑:只有在 URL 实际发生改变时才执行 replaceState,减少不必要的历史记录操作。

构建验证地址:https://chilingling.github.io/tiny-engine/?type=app&id=1&tenant=1

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Bug Fixes
    • Improved URL handling and navigation consistency: tenant switching and app-opening now build and navigate to correct base paths, preserve query parameters, and avoid unnecessary history replacements for more reliable navigation.

@github-actions github-actions Bot added the enhancement New feature or request label Mar 19, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

Walkthrough

Replaced ad-hoc URL string manipulation with deriving BASE_URL via useEnv() and using the URL API across three Vue components to normalize base paths, build tenant/app links, and conditionally update browser history only when the pathname differs.

Changes

Cohort / File(s) Summary
Layout: basePath normalization & history replace
packages/layout/src/Main.vue, packages/layout/src/DesignWorkspace.vue
Import useEnv() and compute basePath from BASE_URL. Use the URL API to set pathname and searchParams; only call window.history.replaceState or assign window.location.href when the computed href differs from current, replacing prior string-concatenation logic.
Workspace: application open URL construction
packages/workspace/application-center/src/Main.vue
Import useEnv() and derive basePath from BASE_URL; construct application links using window.location.origin + basePath plus query params (type=app&id=...&tenant=...) instead of splitting window.location.href.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped through slashes, lost in strings,
Found BASE_URL with tidy wings,
URL API, neat and bright,
Rewrites only when paths don't right,
Now I bound where links take flight. 🎀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes across all three files: normalizing URL pathname construction by replacing inconsistent methods with a unified approach using BASE_URL and proper URL object handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chilingling chilingling changed the title feat(layout): normalize URL pathname and construction fixlayout): normalize URL pathname and construction Mar 19, 2026
@github-actions github-actions Bot added bug Something isn't working and removed enhancement New feature or request labels Mar 19, 2026
@chilingling chilingling changed the title fixlayout): normalize URL pathname and construction fix(layout): normalize URL pathname and construction Mar 19, 2026
@chilingling chilingling marked this pull request as draft March 19, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant