Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <%@ page import="com.byteagenten.examples.html5routing.Route" %>
  2. <html>
  3. <head>
  4. <title>Frontend</title>
  5. <meta charset="UTF-8"
  6. data-base-url="<%=Route.frontend(request)%>/">
  7.  
  8. <link rel="stylesheet" href="<%=Route.asset(request, "styles.css")%>">
  9. <script type="application/javascript" src="<%=Route.asset(request, "app.js")%>"></script>
  10. </head>
  11. <body>
  12. <h1 id="route">Current route: </h1>
  13. <script>
  14.  
  15. // Base URL under which the frontend SPA is running
  16. const meta = document.querySelector('meta');
  17. const baseUrl = meta && meta.dataset.baseUrl || '';
  18.  
  19. // Get complete path after the hostname + port
  20. const pathname = location.pathname;
  21. // Determine current route, by removing the base URL from the path name
  22. const currentRoute = pathname.replace(new RegExp('^' + baseUrl), '');
  23. // Output route
  24. const header = document.getElementById('route');
  25.  
  26. header.innerText += currentRoute;
  27.  
  28. </script>
  29. </body>
  30. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement