Search code examples
urlmeteorroutesflow-router

FlowRouter appending url (route) prefix to all links


Latest meteor JS version breaks FlowRouter or latest FlowRouter version breaks Meteor JS, I can't find the one between the 2 causing the problem Meteor Js I wanted to start a new project using Meteor and staringatlights:flow-router

staringatlights:flow-router
kadira:blaze-layout

I have FlowRouter setup this way:

   var public = FlowRouter.group();

    public.route('/', {
      name: 'home', action(){
        BlazeLayout.render('MainLayout', {main: 'home'});
      }
    });

    var authusers = FlowRouter.group({
        prefix: '/private',
        name: 'authusers'
    });

    authusers.route('/dashboard', {
        name: 'dashboard', action(){
            BlazeLayout.render('DashboardLayout', {dashboards: 'dashboard'});
        }
    });

I have a layout for other templates. The CSS and JS links are from the public folder. I am using a template I don't know the reason why FlowRouter is appending the prefix of the route to all these links.

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="x-ua-compatible" content="ie=edge">

  <title>OL' Tega</title>
  <link rel="stylesheet" href="themes/adminlte3/plugins/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="themes/adminlte3/dist/css/adminlte.min.css">
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>

<template name="DashboardLayout">


    {{> Template.dynamic template=dashboards}}

<script src="themes/adminlte3/plugins/jquery/jquery.min.js"></script>
<script src="themes/adminlte3/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="themes/adminlte3/dist/js/adminlte.js"></script>
<script src="themes/adminlte3/dist/js/demo.js"></script>
<script src="themes/adminlte3/plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="themes/adminlte3/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="themes/adminlte3/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="themes/adminlte3/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="themes/adminlte3/plugins/chartjs-old/Chart.min.js"></script>
<script src="themes/adminlte3/dist/js/pages/dashboard2.js"></script>
</template>

This is the error I am getting. It is not. The router is appending the route prefix to all links.

Refused to apply style from 'http://localhost:3000/private/themes/adminlte3/plugins/font-awesome/css/font-awesome.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
dashboard:1 Refused to apply style from 'http://localhost:3000/private/themes/adminlte3/dist/css/adminlte.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
10Refused to execute script from '<URL>' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/plugins/jquery/jquery.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/plugins/bootstrap/js/bootstrap.bundle.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/dist/js/adminlte.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/dist/js/demo.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/plugins/sparkline/jquery.sparkline.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/plugins/jvectormap/jquery-jvectormap-world-mill-en.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/plugins/slimScroll/jquery.slimscroll.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/plugins/chartjs-old/Chart.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to execute script from 'http://localhost:3000/private/themes/adminlte3/dist/js/pages/dashboard2.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
dashboard:1 Refused to apply style from 'http://localhost:3000/private/themes/adminlte3/plugins/font-awesome/css/font-awesome.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
dashboard:1 Refused to apply style from 'http://localhost:3000/private/themes/adminlte3/dist/css/adminlte.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Solution

  • I believe this is because your urls are relative, and so the browser takes the current url and adds the link path to it.

    To solve this, use add a leading slash so it will resolve as relative to the domain and not the current page. Eg:

    <script src="/themes/adminlte3/plugins/jquery/jquery.min.js"></script>
    <script src="/themes/adminlte3/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="/themes/adminlte3/dist/js/adminlte.js"></script>
    <script src="/themes/adminlte3/dist/js/demo.js"></script>
    <script src="/themes/adminlte3/plugins/sparkline/jquery.sparkline.min.js"></script>
    <script src="/themes/adminlte3/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
    <script src="/themes/adminlte3/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
    <script src="/themes/adminlte3/plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <script src="/themes/adminlte3/plugins/chartjs-old/Chart.min.js"></script>
    <script src="/themes/adminlte3/dist/js/pages/dashboard2.js"></script>