我正在使用Web 组件构建应用程序并使用Vaadin Router进行路由。我有以下项目结构:
索引.html
<html>
<head>
<script type="module" src="app/app.module.js"></script>
</head>
<body>
<mp-app-root></mp-app-root>
</body>
</html>
app.module.js(vaadin 路由器):
(...) multiple imports
import {Router} from '../vaadin-router.js'
// select the DOM node where the route web components are inserted
const outlet = document.querySelector('mp-app-root');
// create a router instance and set the routes config
const router = new Router(outlet);
router.setRoutes([
{path: '/meals', component: 'mp-meal-module'},
{path: '/meals/:id', component: 'mp-meal-detail-module'},
]);
到目前为止,vaadin router 显示mp-app-root
标签中的每个组件。
当我通过<a>
-Tags 调用 URL 时,路由工作正常。但是,如果我将 url 粘贴到地址栏或页面重新加载(例如http://127.0.0.1:8081/meals/1
)组件不会加载,我会收到以下错误:
Uncaught SyntaxError: Unexpected token '<'`
和
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.