forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⬆️ chore: upgrade nextjs to 13.5 (lobehub#219)
* ⬆️ chore: 升级 nextjs 到 13.5 * 🔧 chore: fix theme not work correct after upgrade * 🐛 fix: fix an url hash error when routing
- Loading branch information
Showing
10 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { pathString } from './url'; | ||
|
||
describe('pathString', () => { | ||
it('基本情况', () => { | ||
const result = pathString('/home'); | ||
expect(result).toBe('/home'); | ||
}); | ||
|
||
it('包含查询参数的情况', () => { | ||
const result = pathString('/home', { search: 'id=1&name=test' }); | ||
expect(result).toBe('/home?id=1&name=test'); | ||
}); | ||
|
||
it('包含哈希值的情况', () => { | ||
const result = pathString('/home', { hash: 'top' }); | ||
expect(result).toBe('/home#top'); | ||
|
||
const result2 = pathString('/home', { hash: '#hash=abc' }); | ||
expect(result2).toBe('/home#hash=abc'); | ||
}); | ||
|
||
it('path 参数包含相对路径的情况', () => { | ||
const result = pathString('./home'); | ||
expect(result).toBe('/home'); | ||
}); | ||
|
||
it('path 参数包含绝对路径的情况', () => { | ||
const result = pathString('/home'); | ||
expect(result).toBe('/home'); | ||
}); | ||
|
||
it('path 参数包含协议的情况', () => { | ||
const result = pathString('https://www.example.com/home'); | ||
expect(result).toBe('https://www.example.com/home'); | ||
}); | ||
|
||
it('path 参数包含主机名的情况', () => { | ||
const result = pathString('//www.example.com/home'); | ||
expect(result).toBe('https://www.example.com/home'); | ||
}); | ||
|
||
it('path 参数包含端口号的情况', () => { | ||
const result = pathString('//www.example.com:8080/home'); | ||
expect(result).toBe('https://www.example.com:8080/home'); | ||
}); | ||
|
||
it('path 参数包含特殊字符的情况', () => { | ||
const result = pathString('/home/测试'); | ||
expect(result).toBe('/home/%E6%B5%8B%E8%AF%95'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Build a path string from a path and a hash/search object | ||
* @param path | ||
* @param hash | ||
* @param search | ||
*/ | ||
export const pathString = ( | ||
path: string, | ||
{ | ||
hash = '', | ||
search = '', | ||
}: { | ||
hash?: string; | ||
search?: string; | ||
} = {}, | ||
) => { | ||
const tempBase = 'https://a.com'; | ||
const url = new URL(path, tempBase); | ||
|
||
if (hash) url.hash = hash; | ||
if (search) url.search = search; | ||
return url.toString().replace(tempBase, ''); | ||
}; |