Skip to content

Commit edbc637

Browse files
committed
[fix] Page Switching bugs
1 parent ab5661b commit edbc637

File tree

5 files changed

+36
-27
lines changed

5 files changed

+36
-27
lines changed

ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## Demo
1111

12-
https://web-cell.dev/scaffold/
12+
https://web-cell-scaffold.vercel.app/
1313

1414
## Feature
1515

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cell-router",
3-
"version": "3.0.0-rc.3",
3+
"version": "3.0.0-rc.5",
44
"license": "LGPL-3.0",
55
"description": "Web Component Router based on WebCell & MobX",
66
"keywords": [
@@ -25,7 +25,7 @@
2525
"module": "dist/index.esm.js",
2626
"dependencies": {
2727
"@swc/helpers": "^0.5.3",
28-
"dom-renderer": "^2.0.5",
28+
"dom-renderer": "^2.0.6",
2929
"mobx": ">=6.11",
3030
"regenerator-runtime": "^0.14.1",
3131
"urlpattern-polyfill": "^9.0.0",
@@ -47,21 +47,20 @@
4747
"koapache": "^2.2.2",
4848
"lint-staged": "^15.2.0",
4949
"parcel": "~2.11.0",
50-
"prettier": "^3.2.1",
50+
"prettier": "^3.2.2",
5151
"process": "^0.11.10",
5252
"puppeteer-core": "^21.7.0",
5353
"rimraf": "^5.0.5",
5454
"ts-jest": "^29.1.1",
5555
"typedoc": "^0.25.7",
56-
"typedoc-plugin-mdn-links": "^3.1.11",
56+
"typedoc-plugin-mdn-links": "^3.1.12",
5757
"typescript": "~5.3.3"
5858
},
5959
"scripts": {
6060
"prepare": "husky install",
61-
"start": "cd test/ && npm start",
6261
"set-chrome": "app-find chrome -c",
63-
"preview": "cd test/ && rimraf .parcel-cache/ dist/ && parcel --open",
64-
"pack-preview": "cd test/ && rimraf .parcel-cache/ dist/ && parcel build --public-url=. --dist-dir=../docs/preview/",
62+
"preview": "cd test/ && rimraf ../.parcel-cache/ dist/ && parcel --open",
63+
"pack-preview": "cd test/ && rimraf ../.parcel-cache/ dist/ && parcel build --public-url=. --dist-dir=../docs/preview/",
6564
"pack-dist": "rimraf dist/ && parcel build source/index.ts",
6665
"test": "lint-staged && npm run pack-dist && npm run pack-preview",
6766
"pack-docs": "rimraf docs/ && typedoc source/",

pnpm-lock.yaml

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/History.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ const baseURL = document.querySelector('base')?.href || location.origin,
1616

1717
export class History {
1818
@observable
19-
accessor path = '';
19+
accessor path: string;
2020

2121
@observable
22-
accessor oldPath = '';
22+
accessor oldPath: string;
2323

2424
constructor() {
2525
this.restore();
@@ -63,7 +63,9 @@ export class History {
6363
return parseURLData(after || before);
6464
}
6565

66-
static match(pattern: string, path: string) {
66+
static match(pattern: string, path?: string) {
67+
if (!path) return;
68+
6769
const { pathname, hash } =
6870
new URLPattern(pattern, baseURL).exec(
6971
new URL(path.split('?')[0], baseURL)

source/Router.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,21 @@ export class CellRoute extends HTMLElement implements WebCell {
5252
return History.match(this.path, history.oldPath);
5353
}
5454

55+
pageStyle: WebCellProps['style'] = {
56+
position: 'absolute',
57+
top: '0',
58+
left: '0',
59+
width: '100%'
60+
};
61+
5562
connectedCallback() {
5663
if (getComputedStyle(this.parentElement).position === 'static')
5764
this.parentElement.style.position = 'relative';
5865
}
5966

6067
render() {
61-
const { inAnimation, outAnimation, matched, oldMatched } = this,
68+
const { pageStyle, inAnimation, outAnimation, matched, oldMatched } =
69+
this,
6270
Tag = this.component,
6371
{ path, oldPath } = history;
6472

@@ -68,7 +76,7 @@ export class CellRoute extends HTMLElement implements WebCell {
6876
component={props => (
6977
<Tag
7078
{...props}
71-
style={{ position: 'absolute', top: '0', left: '0' }}
79+
style={pageStyle}
7280
{...matched}
7381
{...History.dataOf(path)}
7482
{...{ path, history }}
@@ -81,7 +89,7 @@ export class CellRoute extends HTMLElement implements WebCell {
8189
component={props => (
8290
<Tag
8391
{...props}
84-
style={{ position: 'absolute', top: '0', left: '0' }}
92+
style={pageStyle}
8593
{...oldMatched}
8694
{...History.dataOf(oldPath)}
8795
path={oldPath}

0 commit comments

Comments
 (0)