2

How do single page app router libraries (eg. react-router) load a path without getting document not found? I get that they must intercept window.location.pathname which then allows them to display views but how do they prevent getting a document not found error when loading a path initially?

Fergal
  • 5,213
  • 6
  • 35
  • 44
  • What are you trying to achieve? – guest271314 Jul 27 '17 at 00:36
  • Apart from adding to my overall understanding of how browsers work, I'm trying to implement my own small routing library. I'm writing an app in pure JS, no frameworks (there are reasons for this), but I would like to be able to having routing capability. – Fergal Jul 27 '17 at 01:05
  • What do you mean by "routing" at a single page application? Why do you not utilize fragment identifiers? – guest271314 Jul 27 '17 at 01:07
  • Yes I could absolutely use fragment identifiers, or query parameters for that matter. I'm interested in how router libraries like react-router or vue-router manage to intercept a deep URL path in single page app. – Fergal Jul 27 '17 at 01:17
  • Have not tried react-router or vue-router. One approach would be to use `ServiceWorker` to respond to all requests – guest271314 Jul 27 '17 at 01:18
  • Interesting. How would that be achieved? – Fergal Jul 27 '17 at 01:22
  • 1
    See, for example, [Chrome extension: Block page items before access](https://stackoverflow.com/q/41281291/) – guest271314 Jul 27 '17 at 01:28
  • Seems like a viable solution. I wonder if this is how the afore mentioned libraries do it? – Fergal Jul 27 '17 at 01:42

0 Answers0