How to use the san-router.router.listen function in san-router

To help you get started, we’ve selected a few san-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ecomfe / santd / site / src / index.js View on Github external
attached() {
        const that = this;
        // 错误提示
        window.addEventListener('error', this.handleError.bind(this), false);

        // 添加路由
        router.add({
            rule: '/:type/:id',
            handler(e) {
                // console.log(e); // eslint-disable-line
            }
        });

        // 路由监听
        router.listen(e => {
            const query = e.query;
            if (e.path === '/') {
                that.handleRedirect({key: defaultPath});
                that.data.set('currentPath', defaultPath);
            }
            else {
                that.data.set('currentPath', e.path);
                document.getElementById('content').innerHTML = '';
                that.data.set('content', '');
                if (query.type === 'docs') {
                    import(
                        /* webpackChunkName: "docs" */
                        `@docs/${query.id}.md?exportType=html`
                    ).then(({default: html}) => {
                        that.data.set('content', html);
                    }).catch(e => {
github ecomfe / san-realworld-app / src / index.js View on Github external
function bootstrap() {
    axios.defaults.validateStatus = function (status) {
        return status >= 200 && status < 500;
    };

    (new Header).attach(document.getElementById('header'));
    (new Footer).attach(document.getElementById('footer'));

    router.listen(e => {
        store.dispatch(ActionTypes.ERRORS_CLEAR);
        store.dispatch(UserActionTypes.GET);
    });

    router.add({rule: '/', Component: Home});
    router.add({rule: '/tag/:tag', Component: Home});
    router.add({rule: '/my-feed', Component: Home});
    router.add({rule: '/login', Component: Login});
    router.add({rule: '/register', Component: Register});
    router.add({rule: '/settings', Component: Setting});
    router.add({rule: '/profile/:user', Component: ProfileMy});
    router.add({rule: '/profile/:user/favorites', Component: ProfileFavorited});
    router.add({rule: '/editor', Component: ArticleEdit});
    router.add({rule: '/editor/:slug', Component: ArticleEdit});
    router.add({rule: '/article/:slug', Component: ArticleView});

san-router

Router for San

MIT
Latest version published 7 months ago

Package Health Score

59 / 100
Full package analysis

Similar packages