Giter Club home page Giter Club logo

vue-router-gwt's Introduction

Vue Router GWT

A JsInterop wrapper for Vue Router to use in Vue GWT.

This wrapper allows you to use Vue Router in Vue GWT apps.

How to Set It Up

Make sure you have set up your Vue GWT project.

Then follow these steps:

✅ Add the Maven Dependency

<project>
    <dependencies>
        ...
        <dependency>
            <groupId>com.axellience</groupId>
            <artifactId>vue-router-gwt</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
</project>

✅ Add the GWT dependency

Add this in your app .gwt.xml file:

<inherits name='com.axellience.vueroutergwt.VueRouterGwt'/>

✅ Call VueRouter.init()

This will inject the javascript of VueRouter in your page. You should do it right under your Vue.init().

VueGWT.init();
VueRouter.init();

If you already have the VueRouter javascript included in your page by another way, you don't have to call VueRouter.init().

How to Use It

Let's see a simple example. We have an application with a RootComponent and we want to set up routing for two Components: FooComponent and BarComponent.

Foo and Bar Components

FooComponent

@Component
public class FooComponent implements IsVueComponent {
}
<div>Hello from Foo!</div>

BarComponent

@Component
public class BarComponent implements IsVueComponent {
}
<div>Hello from Bar!</div>

RootComponent

Ok this Component is going to be a little more interesting.

<div>
    <h1>Hello App!</h1>
    <p>
        <router-link to="/foo">Go to Foo</router-link>
        <router-link to="/bar">Go to Bar</router-link>
    </p>
    <router-view></router-view>
</div>

router-link Components above in the template will be replaced by a elements at runtime. router-view will contain the Component for the active route (either FooComponent or BarComponent).

Let's see how we declare our routes:

// First, we declare a class to configure the routing and register it on some component options
public class RoutesConfig implements CustomizeOptions {
    @Override
    public void customizeOptions(VueComponentOptions vueComponentOptions)
    {
        // We first create an object to hold our Router options
        RouterOptions routerOptions = new RouterOptions();
        
        // We add the routes to our options by passing
        // their path and the Constructor of the Component we want to display on them
        routerOptions
            .addRoute("/foo", FooComponentFactory.get())
            .addRoute("/bar", BarComponentFactory.get());

        // We the create our router
        VueRouter vueRouter = new VueRouter(routerOptions);
        
        // And set it on our Component options
        vueComponentOptions.set("router", vueRouter);
    }
}
// Then we bind this class to our RootComponent so it customize it's options
@Component(customizeOptions = RoutesConfig.class)
public class RootComponent implements IsVueComponent {
}

Easy, right?

If you want more documentation on the API you can checkout the official Vue Router documentation.

Who Made This?

Vue GWT is developed by the awesome people at
GenMyModel

vue-router-gwt's People

Contributors

adrienbaron avatar jtrentes avatar nightfox7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.