File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -534,6 +534,18 @@ describe('Router', () => {
534534 } )
535535 } )
536536
537+ // https://github.com/vuejs/router/issues/2187
538+ it ( 'keeps a consistent value on fullPath when resolving' , async ( ) => {
539+ const { router } = await newRouter ( )
540+ const targetLoc = '/search#/?redirect=%2F%3Fid%3D1%23%2Fabc'
541+ expect ( router . resolve ( targetLoc ) . fullPath ) . toBe ( targetLoc )
542+ await router . push ( targetLoc )
543+ expect ( router . currentRoute . value . fullPath ) . toBe ( targetLoc )
544+ await router . push ( '/' )
545+ await router . replace ( targetLoc )
546+ expect ( router . currentRoute . value . fullPath ) . toBe ( targetLoc )
547+ } )
548+
537549 describe ( 'navigation cancelled' , ( ) => {
538550 async function checkNavigationCancelledOnPush (
539551 target ?: RouteLocationRaw | false
Original file line number Diff line number Diff line change @@ -525,13 +525,19 @@ export function createRouter(options: RouterOptions): Router {
525525 // we need to run the decoding again
526526 matchedRoute . params = normalizeParams ( decodeParams ( matchedRoute . params ) )
527527
528- const fullPath = stringifyURL (
529- stringifyQuery ,
530- assign ( { } , rawLocation , {
531- hash : encodeHash ( hash ) ,
532- path : matchedRoute . path ,
533- } )
534- )
528+ const fullPath =
529+ // @ts -expect-error: the rawLocation doesn't normally have a fullPath
530+ // but sometimes it gets noramlized before being passed to resolve and we can
531+ // resue it to avoid encoding an unencoded path from the user in order to be closer
532+ // to the URL constructor behavior. vuejs/router#2187
533+ rawLocation . fullPath ||
534+ stringifyURL (
535+ stringifyQuery ,
536+ assign ( { } , rawLocation , {
537+ hash : encodeHash ( hash ) ,
538+ path : matchedRoute . path ,
539+ } )
540+ )
535541
536542 const href = routerHistory . createHref ( fullPath )
537543 if ( __DEV__ ) {
You can’t perform that action at this time.
0 commit comments