ItalyPaleAle / svelte-spa-router

Router for SPAs using Svelte 3
MIT License
1.54k stars 105 forks source link

Ensure hash is present in URL #272

Closed talwat closed 1 year ago

talwat commented 2 years ago

Hi!

Is there any way to redirect or change the URL if the hash is not present?

For example, if they go to mywebsite.com it will redirect them to mywebsite.com/#/?

And if they go to mywebsite.com/# it will also redirect them to mywebsite.com/#/.

ItalyPaleAle commented 1 year ago

You can certainly do that in your app's "init" code!

For example, in the app.js file (or whatever your "main" file is), you can import {location, replace} from 'svelte-spa-router' then get the value of $location, and if it's not #/, then use replace() to redirect the user.