File tree 1 file changed +18
-6
lines changed 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -84,9 +84,14 @@ export function createRouter(
84
84
if ( inBrowser ) {
85
85
nextTick ( ( ) => {
86
86
if ( targetLoc . hash && ! scrollPosition ) {
87
- const target = document . querySelector (
88
- decodeURIComponent ( targetLoc . hash )
89
- ) as HTMLElement
87
+ let target : HTMLElement | null = null
88
+ try {
89
+ target = document . querySelector (
90
+ decodeURIComponent ( targetLoc . hash )
91
+ ) as HTMLElement
92
+ } catch ( e ) {
93
+ console . warn ( e )
94
+ }
90
95
if ( target ) {
91
96
scrollTo ( target , targetLoc . hash )
92
97
return
@@ -176,9 +181,16 @@ export function useRoute(): Route {
176
181
}
177
182
178
183
function scrollTo ( el : HTMLElement , hash : string , smooth = false ) {
179
- const target = el . classList . contains ( '.header-anchor' )
180
- ? el
181
- : document . querySelector ( decodeURIComponent ( hash ) )
184
+ let target : Element | null = null
185
+
186
+ try {
187
+ target = el . classList . contains ( '.header-anchor' )
188
+ ? el
189
+ : document . querySelector ( decodeURIComponent ( hash ) )
190
+ } catch ( e ) {
191
+ console . warn ( e )
192
+ }
193
+
182
194
if ( target ) {
183
195
const targetTop = ( target as HTMLElement ) . offsetTop
184
196
// only smooth scroll if distance is smaller than screen height.
You can’t perform that action at this time.
0 commit comments