Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing custom History object #173

Closed
wants to merge 2 commits into from

Conversation

notpushkin
Copy link

This exposes a param on the router called history. By default, it will use globalHistory, but we can pass an API-compatible history object and it will be used instead. For example, we can force it to use a memory source (closes #153):

<script>
  import { Router, Link, Route } from "svelte-routing";
  import {
    createHistory,
    createMemorySource,
  } from "svelte-routing/src/history";
  // ...import routes...

  const source = createMemorySource();
  let url = source.location.pathname;
  const history = createHistory(source);
</script>

<Router url="{url}">
  <nav>
    <Link to="/">Home</Link>
    <Link to="about">About</Link>
    <Link to="blog">Blog</Link>
  </nav>
  <div>
    <Route path="blog/:id" component="{BlogPost}" />
    <Route path="blog" component="{Blog}" />
    <Route path="about" component="{About}" />
    <Route path="/"><Home /></Route>
  </div>
</Router>

I've also noticed that the History type is kinda like the history package used in React Router – apart from navigate vs. push/replace, it seems like a drop-in replacement. You might want to switch to that instead, as it seems like a good abstraction overall – but that's up to you :)

@notpushkin
Copy link
Author

Note that this breaks the import { navigate } from "svelte-routing" function. I'm not yet sure how to replace it, since we have to call getContext during component initialization, but I think it can be dealt with somehow (pass history object to the route?).

@krishnaTORQUE
Copy link
Collaborator

Hi
I forked svelte-routing > https://github.com/krishnaTORQUE/svelte-routing-next.
And I merged your PR there.
Please let me know if you have any query.
Thanks.

@krishnaTORQUE
Copy link
Collaborator

MERGED
View Changelog: https://github.com/EmilTholin/svelte-routing/blob/master/CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question: Can I use router without modifying browser URL address?
2 participants