Skip to content

Commit

Permalink
fix: mount refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Nov 11, 2022
1 parent 49fbed6 commit 9926957
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export interface RouterState {
location: Location
matches: RouteMatch[]
lastUpdated: number
loaderData: unknown
currentAction?: ActionState
latestAction?: ActionState
actions: Record<string, Action>
Expand Down Expand Up @@ -366,7 +365,6 @@ export function createRouter<
matches: [],
actions: {},
loaders: {},
loaderData: {} as any,
lastUpdated: Date.now(),
isFetching: false,
isPreloading: false,
Expand Down Expand Up @@ -409,11 +407,12 @@ export function createRouter<
// to the current location. Otherwise, load the current location.
if (next.href !== router.location.href) {
router.__.commitLocation(next, true)
} else {
router.loadLocation()
}

const unsub = history.listen((event) => {
router.loadLocation()

const unsub = router.history.listen((event) => {
console.log(event.location)
router.loadLocation(
router.__.parseLocation(event.location, router.location),
)
Expand All @@ -440,6 +439,15 @@ export function createRouter<
},

update: (opts) => {
const newHistory = opts?.history !== router.history
if (!router.location || newHistory) {
if (opts?.history) {
router.history = opts.history
}
router.location = router.__.parseLocation(router.history.location)
router.state.location = router.location
}

Object.assign(router.options, opts)

const { basepath, routeConfig } = router.options
Expand Down Expand Up @@ -487,7 +495,7 @@ export function createRouter<
router.cancelMatches()

// Match the routes
const matches = router.matchRoutes(location.pathname, {
const matches = router.matchRoutes(router.location.pathname, {
strictParseParams: true,
})

Expand Down Expand Up @@ -1211,9 +1219,6 @@ export function createRouter<
},
}

router.location = router.__.parseLocation(history.location)
router.state.location = router.location

router.update(userOptions)

// Allow frameworks to hook into the router creation
Expand Down

0 comments on commit 9926957

Please sign in to comment.