Coder Social home page Coder Social logo

alpinejs-router's People

Contributors

shaunlee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ilvmd wttw

alpinejs-router's Issues

Page reload changes location to server root

Hi, I like your approach and would like to use your alpinejs-router in a project. However I need a working router for a page in a sub directory of the servers root like /calculator/. When I load your example the first time the URL is

http://127.0.0.1:5500/examples/index.html, however all routes in the example transform the URL to http://127.0.0.1:5500/#/ instead of http://127.0.0.1:5500/examples/#/.

Is there any way I can configure the router to work in a sub directory of the servers root?

Thanks, Bernd

Provide API of `$router` in JS

Hey, thanks for your work.

I am trying to do something in the EventListener of alpine:init depending on the current route. I do not seem to be able to do that, since the magic property $router is not available in JS context.

Is there any way to expose/export an instance of the route object of index.js so the same functions which are accessible in HTML are accessible in JS?

need to support relative path to files

when using template="./login.html", it still references the login.html at the project root instead of the same folder of current file, no difference of template="/login.html"

Catch-all fallback route for Vite [[question]]

Hi Shaunlee, first thanks for this amazing code!

For the web mode you say:

Not to worry: To fix the issue, all you need to do is add a simple catch-all fallback route to your server. If the URL doesn't match any static assets, it should serve the same index.html page that your app lives in. Beautiful, again!

But I don't fully understand this. I'm using Vite (no-vue, just Alpine) and I don't know how to add a catch-all fallback route.

This is the piece I'm using with no luck. Could you help me with this?

  server: {
    proxy: {
      '/hello/world': {
        target: 'http://localhost:3000/',
        changeOrigin: true,
        secure: false,
        configure: (proxy, _options) => {
          proxy.on('error', (err, _req, _res) => {
            console.log('proxy error', err);
          });
          proxy.on('proxyReq', (proxyReq, req, _res) => {
            console.log('Sending Request to the Target:', req.method, req.url);
          });
          proxy.on('proxyRes', (proxyRes, req, _res) => {
            console.log('Received Response from the Target:', proxyRes.statusCode, req.url);
          });
        }
      }
    }
  }

Dynamic Routes

Hello, how to add dynamic routes?, there is a fuction like $router.addRoute ?
thx for your work.

Example does not work ?

From your example (using cdn)

 <div  x-data>
        <a x-link href="/hello/world">Hello World</a>

        <template x-route="/hello/:name">
            <div>Say hello to <span x-text="$router.params.name"></span></div>
        </template>

    </div>

When clicking, browser will just try to go to /hello/world, should there be a prevent.default or something ?

Path attribute of router not properly initialised in v1.2.12

Unfortunately, there seems to be an issue with the new version. At least the path property of $router is not properly initialised when visiting a path, and only changes to the right value some time after. This worked in 1.2.9.

Minimal reproducible example:

index.html

<body x-data x-init="fetchData($router)">
    <p>Data is: <span x-text="$store.someContent"></span></p>
    <script src="/app.js"></script>
</body>

app.js

document.addEventListener('alpine:init', () => {
  Alpine.store('someContent', "")

})

function fetchData(r) {
  router = Alpine.$router ? Alpine.$router : r;

  Alpine.effect(() => console.log("router.path: " + router.path))

  if (router.path == '/fetch'){
    Alpine.store('someContent', "Hello World")
  }
}

Result for v1.2.9
image

Result for v1.2.12
image

Thank you for your continuous effort.

$router is not defined

$router is not defined

with both cdn.min.js and es6.min.js

Used with vite js and electron js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.