erikringsmuth / app-router

Router for Web Components
https://erikringsmuth.github.io/app-router/
MIT License
610 stars 83 forks source link

Preload route #166

Closed bohdaq closed 7 years ago

bohdaq commented 7 years ago

Hey,

How can I preload the route, before user clicks on link?

Thanks!

jmalonzo commented 7 years ago

@bohdaq One technique is to use a module bundler that does code-splitting (e.g. webpack) and split your bundles based on the routes set in your app. Then use <link rel="preload"> to load your route-specific bundles.

bohdaq commented 7 years ago

ty jmalonzo!

going to try now

bohdaq commented 7 years ago

jmalonzo is there a possibility to change the location and let the router omit this one specific change?

jmalonzo commented 7 years ago

How do you mean?

bohdaq commented 7 years ago

For example my window.location.pathname is "/new"

I need to change it to "/task/1" without router refresh the view.

My configuration:

      <app-router mode="pushstate" on-state-change="highlightMenu" app-type="internal">

        <app-route path="/task/:key" element="dynamic-task-view"></app-route>
        <app-route path="/new" element="start-new-workflow-categories"></app-route>

      </app-router>
bohdaq commented 7 years ago

Looks like I found the way using history.replaceState

Thanks!

jmalonzo commented 7 years ago

@bohdaq You'd need to ensure that when you click on a link that goes to a route (e.g. <a href="/new">), the browser won't trigger a "refresh". You can use pushstate or pushstate-anchor (https://github.com/erikringsmuth/pushstate-anchor).

bohdaq commented 7 years ago

t- timing 👍