All Projects → raniesantos → vue-error-page

raniesantos / vue-error-page

Licence: other
[NO LONGER MAINTAINED] Provides a wrapper for router-view that allows you to show error pages without changing the URL.

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects

Projects that are alternatives of or similar to vue-error-page

STCRouter
基于标准URL的iOS路由系统,可实现业务模块组件化,控制器之间零耦合,可实现黑白名单控制,可进行native降级到hybrid。
Stars: ✭ 19 (-63.46%)
Mutual labels:  routes, routing, route
free404
A series of creative 404 pages designed to pleasantly surprise your users if an error were to ever occur.
Stars: ✭ 58 (+11.54%)
Mutual labels:  error-page, 404, 404-pages
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (-73.08%)
Mutual labels:  routes, routing
koii
A simple middleware for displaying routes in an express application
Stars: ✭ 73 (+40.38%)
Mutual labels:  routing, route
Express Env Example
A sample express environment that is well architected for scale. Read about it here:
Stars: ✭ 130 (+150%)
Mutual labels:  routes, routing
node-match-path
Matches a URL against a path. Parameters, wildcards, RegExp.
Stars: ✭ 30 (-42.31%)
Mutual labels:  routing, route
path-to-regexp-php
PHP port of https://github.com/pillarjs/path-to-regexp
Stars: ✭ 21 (-59.62%)
Mutual labels:  routing, route
laroute
Generate Laravel route URLs from JavaScript.
Stars: ✭ 33 (-36.54%)
Mutual labels:  routes, routing
ertuo
Ertuo: quick routing for PHP
Stars: ✭ 29 (-44.23%)
Mutual labels:  routes, routing
urltree
Named URL data structure with support for URL building.
Stars: ✭ 36 (-30.77%)
Mutual labels:  routes, routing
router
Bidirectional Ring router. REST oriented. Rails inspired.
Stars: ✭ 78 (+50%)
Mutual labels:  routes, routing
Universal Router
A simple middleware-style router for isomorphic JavaScript web apps
Stars: ✭ 1,598 (+2973.08%)
Mutual labels:  routes, routing
404-pages
Custom 404 pages pack for websites
Stars: ✭ 44 (-15.38%)
Mutual labels:  404, 404-pages
url-trailing-slash
Allows enforcing URL routes with or without trailing slash
Stars: ✭ 35 (-32.69%)
Mutual labels:  routing, route
404-to-301
Manage 404 errors on your WordPress site and redirect them to any pages using 301 redirect for SEO
Stars: ✭ 11 (-78.85%)
Mutual labels:  404, 404-pages
routex.js
🔼 Alternative library to manage dynamic routes in Next.js
Stars: ✭ 38 (-26.92%)
Mutual labels:  routes, routing
Next Routes
Universal dynamic routes for Next.js
Stars: ✭ 2,354 (+4426.92%)
Mutual labels:  routes, routing
Stplanr
Sustainable transport planning with R
Stars: ✭ 352 (+576.92%)
Mutual labels:  routes, routing
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (+467.31%)
Mutual labels:  routes
Php Wss
Web-socket server/client with multi-process and parse templates support on server and send/receive options on client
Stars: ✭ 117 (+125%)
Mutual labels:  routes

vue-error-page [NO LONGER MAINTAINED]

Latest Version on NPM Software License PRs Welcome donate

Provides a wrapper for router-view that allows you to show error pages without changing the URL.


Why?

Because:


Install

You can install this package via yarn (or npm):

$ yarn add vue-error-page

Usage

Setup

This package depends on a global event bus in order to emit events that will show the error page. You must first define an event bus on the window object. By default it looks for the eventBus key but you can configure this to use a different key.

import Vue from 'vue';
import ErrorPage from 'vue-error-page';

window.eventBus = new Vue();

Vue.use(ErrorPage);

Options

Vue.use(ErrorPage, {
    tagName: 'app-view',
    bus: 'eventBus',
    event: 'error-page',
    resolver: (component) => {
        return require('./views/Errors/' + component).default;
    }
});
Option Default Value Description
tagName 'app-view' The name of the component that wraps router-view.
bus 'eventBus' The name of the event bus. (Must be defined on window.)
event 'error-page' The name of the event being emitted and listened to.
resolver (component) => { return component; } This is essentially just a shortcut for importing the component. This will not work with SSR.

The wrapper component

Then you can swap router-view with app-view (or whatever you defined for tagName).

<template>
    <div>
        <header></header>
        <nav></nav>
        <app-view></app-view>
        <footer></footer>
    </div>
</template>

Triggering the error page

Finally, you can use the $_error() method injected into all components. You can call it to display a specific error page.

Example route

{
    path: '/profile/:username',
    component: require('./views/Profile').default
}

views/Errors/NotFound.vue

<template>
    <div>
        <h1>404 Error</h1>
        <p>The resource could not be found.</p>
        <router-link to="/" exact>
            Go to home page
        </router-link>
    </div>
</template>

views/Profile.vue

import NotFound from './views/Errors/NotFound';

axios.get('/profile/' + this.$route.params.username)
    .then((response) => {
        // user was found
    })
    .catch((error) => {
        if (error.response.status === 404) {
            this.$_error(NotFound);
        }
    });

If you decided to define a resolver, you can directly specify the filename of the component like this this.$_error('NotFound').

Additionally, if you name your error components after status codes like this 404.vue, you can trigger error pages like this this.$_error(404).

Passing additional data to the error page

You can pass a payload as an additional argument to $_error().

this.$_error(404, {
    username: this.$route.params.username
});

The payload will be available as a prop in the component.

<template>
    <div>
        <h1>404 Error</h1>
        <p>User {{ payload.username }} not found.</p>
        <router-link to="/" exact>
            Go to home page
        </router-link>
    </div>
</template>

<script>
export default {
    props: ['payload']
};
</script>

Contributing

Please see CONTRIBUTING for details.


License

Released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].