Is it possible not to push unnecessary state when clicking an <a> element?
- Vorherrschende Sprache
- JavaScript
- Sterne
- 31.5k
- Forks
- 5.8k
- Ø Merge
- 9 T. 8 Std.
- Gemergte PRs (30 T.)
- 2
Beschreibung
## Feature request
#### Problem or desire
I click an element which has the href just like the location.href when setting routerMode to "history", and then it pushes a new state which is not necessary.
It might be better to use history.back() than history.pushState() when clicking an element which has the href just like the location.href of the previous page in session history.
#### Proposal
Do nothing when clicking an element which has the href just like the location.href.
Use history.back() when clicking an element which has the href just like the location.href of the previous page in session history.
#### Implementation
Just change the onchange function to something like this:
```
e.prototype.onchange = function (i) {
void 0 === i &&
(i = d),
p(
'click',
function (e) {
var n = 'A' === e.target.tagName ? e.target : e.target.parentNode;
n &&
'A' === n.tagName &&
!g(n.href) &&
(
e.preventDefault(),
n = n.href,
n === location.href ? 1 : //Add
n === hrefPre ? window.history.back() : //Add(hrefPre is used to record the href before)
window.history.pushState({
key: n
}, '', n),
i({
event: e,
source: 'navigate'
})
)
}
),
p('popstate', function (e) {
i({
event: e,
source: 'history'
})
})
}
```
Beitragsleitfaden
Rechercherichtung
Beginne damit, die JavaScript-Quelldatei zu finden, die e.prototype.onchange enthält, und lies deren Behandlung von click und popstate. Reproduziere die im Issue beschriebenen Fälle für Anker/History und verifiziere anschließend, dass die Navigation zum selben Ort nichts tut und die Navigation zur vorherigen History-URL wie vorgeschlagen funktioniert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- frontend, web-dev
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100