Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #104843
    Dawud Tan
    Participant

    I got error when try to use router with path to an external HTML:

    const router = new Smart.Router('tampilanUtamanya', '${mvc.basePath}/coba');
    router.cache = true;
    
    router.setRoutes([{
    path: '/',
    template: 'tampilanBeranda',
    title: 'Rumahnya'
    },
    {
    path: '/cip',
    template: '.${mvc.basePath}/tentang/templatTentang.htm',
    styleUrls: ['./tentang/coba.css'],
    scriptUrls: ['./tentang/coba.js'],
    title: 'Tentangnya'
    },
    {
    path: '/hubungi',
    template: 'templatHubungi',
    title: 'Hubungilah'
    }
    ]);
    
    router.route('/');
    #104844

    Hi,

    Can you please share what error are you receiving?
    A steps for reproducing the error would also be useful.

    Best Regards,
    Svetoslav Borislavov

    Smart UI Team
    https://www.htmlelements.com/

    #104848
    Dawud Tan
    Participant

    the error is my route is not functioning as expected when I specify a path to an external HTML file, but instead it is just showing 404 not found error, the route configuration that I have passed as parameter to the setRoutes method is correct as explained in the documentation:

    template: string - either the id of a local HTMLTemplateElement or a path to an external HTML file. The HTML contents serves as a template for the view of the route.

    $(() => {
    const router = new Smart.Router('tampilanUtamanya', '${mvc.basePath}/coba');
    
    router.setRoutes([{
    path: '/',
    template: 'tampilanBeranda',
    title: 'Rumahnya'
    },
    {
    path: '/cip',
    template: './tentang/templatTentang.htm',
    title: 'Tentangnya'
    },
    {
    path: '/hubungi',
    template: 'templatHubungi',
    title: 'Hubungilah'
    },
    {
    path: '/lainu',
    template: 'laine',
    title: 'lain2'
    }
    ]);
    
    router.route('/');
    });

    When I specify just the id of a local HTMLTemplateElement, it could be functioning as expected.

    • This reply was modified 1 year, 6 months ago by Dawud Tan.
    #104850
    Dawud Tan
    Participant

    the smart.router.js that I used come from Smart HTML’s Github Repository https://github.com/HTMLElements/smart-webcomponents/releases/tag/v15.0.0
    in the source directory: /source/smart.router.js

    • This reply was modified 1 year, 6 months ago by Dawud Tan.
    #104856
    admin
    Keymaster

    Hi,

    Have you checked https://www.htmlelements.com/docs/router/ which shows how to configure the router?

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.