Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): router遷移時にmatchAllに入った場合一度location.hrefを経由するように #13509

Merged
merged 5 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-

### Client
-
- Fix: 一部のページ内リンクが正しく動作しない問題を修正

### Server
-
Expand Down
24 changes: 14 additions & 10 deletions packages/frontend/src/nirax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class Router extends EventEmitter<RouterEvent> implements IRouter {
return check(this.routes, _parts);
}

private navigate(path: string, key: string | null | undefined, emitChange = true, _redirected = false): Resolved {
private navigate(path: string, key: string | null | undefined, emitChange: boolean | 'whenFound' = 'whenFound', _redirected = false): Resolved {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここ変える必要あるかしら

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matchAllのときでもルート遷移は発生してしまうのでそれを防止するオプションがwhenFoundだけどそれをemitChangeのデフォルト動作にしてしまってもいいか

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうした

const beforePath = this.currentPath;
this.currentPath = path;

Expand Down Expand Up @@ -373,7 +373,7 @@ export class Router extends EventEmitter<RouterEvent> implements IRouter {
this.currentRoute.value = res.route;
this.currentKey = res.route.globalCacheKey ?? key ?? path;

if (emitChange) {
if (emitChange === true || (emitChange === 'whenFound' && res.route.path !== '/:(*)')) {
this.emit('change', {
beforePath,
path,
Expand All @@ -397,7 +397,7 @@ export class Router extends EventEmitter<RouterEvent> implements IRouter {
return this.currentKey;
}

public push(path: string, flag?: any) {
public push(path: string, flag?: any, useBrowserWhenNotFound = true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

引数追加する必要性あるかしら

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ないかも

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

けした

const beforePath = this.currentPath;
if (path === beforePath) {
this.emit('same');
Expand All @@ -408,13 +408,17 @@ export class Router extends EventEmitter<RouterEvent> implements IRouter {
if (cancel) return;
}
const res = this.navigate(path, null);
this.emit('push', {
beforePath,
path: res._parsedRoute.fullPath,
route: res.route,
props: res.props,
key: this.currentKey,
});
if (useBrowserWhenNotFound && res.route.path === '/:(*)') {
location.href = path;
} else {
this.emit('push', {
beforePath,
path: res._parsedRoute.fullPath,
route: res.route,
props: res.props,
key: this.currentKey,
});
}
}

public replace(path: string, key?: string | null) {
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/vite.config.local-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const devConfig = {
},
'/url': httpUrl,
'/proxy': httpUrl,
'/_info_card_': httpUrl,
'/bios': httpUrl,
'/cli': httpUrl,
},
},
build: {
Expand Down
Loading