kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 193 forks source link

Error: No such function: pathFor #727

Closed AlbinoGeek closed 6 years ago

AlbinoGeek commented 6 years ago

Description of Problem

pathFor is not defined

routes.coffee:16 Uncaught ReferenceError: pathFor is not defined

Exception in defer callback: Error: No such function: pathFor
    at http://localhost:3000/packages/blaze.js?hash=3214:15
    at Spacebars.call (http://localhost:3000/packages/spacebars.js?hash=172:18)

Source Code of Problem

client/home.html

<template name="home">
  <p>Please <a href="{{pathFor 'login'}}">Login</a> to continue.</p>
</template>

client/routes.coffee

FlowRouter.route '/', {
  action: -> BlazeLayout.render 'applicationLayout', main: 'home'
  name: 'Home'
}

FlowRouter.route '/login', {
  action: -> BlazeLayout.render 'applicationLayout', main: 'login'
  name: 'Login'
}

# tried to debug with:
console.log(pathFor)

Output of meteor list

autopublish            1.0.7  (For prototyping only) Publish the entire database to all clients
blaze-html-templates   1.1.2  Compile HTML templates into reactive UI with Meteor Blaze
coffeescript           2.0.2_1  Javascript dialect with fewer braces and semicolons
ecmascript             0.9.0  Compiler plugin that supports ES2015+ in all .js files
es5-shim               4.6.15  Shims and polyfills to improve ECMAScript 5 support
insecure               1.0.7  (For prototyping only) Allow all database writes from the client
kadira:blaze-layout    2.3.0  Layout Manager for Blaze (works well with FlowRouter)
kadira:flow-router     2.12.1  Carefully Designed Client Side Router for Meteor
meteor-base            1.2.0  Packages that every Meteor app needs
mobile-experience      1.0.5  Packages for a great mobile user experience
mongo                  1.3.0  Adaptor for using MongoDB and Minimongo over DDP
reactive-var           1.0.11  Reactive variable
shell-server           0.3.0  Server-side component of the `meteor shell` command.
standard-minifier-css  1.3.5  Standard css minifier used with Meteor apps by default.
standard-minifier-js   2.2.1  Standard javascript minifiers used with Meteor apps by default.
tracker                1.1.3  Dependency tracker to allow reactive callbacks

Yet in another project with the same packages/versions it works.

I have tried re-making this project 6 times and am tearing my hair out now.

AlbinoGeek commented 6 years ago

https://github.com/arillo/meteor-flow-router-helpers

arillo:flow-router-helpers does not install (says it would downgrade templating and coffeescript)

Is there a flow-router way to get a path for a route?

 => Errors while adding packages:

While selecting package versions:
error: Potentially incompatible change required to top-level dependency: coffeescript 1.12.7_3, was 2.0.2_1.
Constraints on package "coffeescript":
* coffeescript@1.0.4 <- arillo:flow-router-helpers 0.5.2
* coffeescript@1.0.4 <- zimme:active-route 2.3.2 <- arillo:flow-router-helpers 0.5.2

To allow potentially incompatible changes to top-level dependencies, you must pass --allow-incompatible-update on the command line.
AlbinoGeek commented 6 years ago

Might be a problem with the other package instead: https://github.com/arillo/meteor-flow-router-helpers/issues/41

Although this means flow-router provides no way to "link to" a route natively?

AlbinoGeek commented 6 years ago

# return path
pathFor = (path, view = {hash:{}}) ->
  throw new Error('no path defined') unless path
  # set if run on server
  view = hash: view unless view.hash
  if path.hash?.route?
    view = path
    path = view.hash.route
    delete view.hash.route
  query = if view.hash.query then FlowRouter._qs.parse(view.hash.query) else {}
  hashBang = if view.hash.hash then view.hash.hash else ''
  FlowRouter.path(path, view.hash, query) + (if hashBang then "##{hashBang}" else '')

Template.registerHelper 'pathFor', pathFor

Closing this issue, since the problem was with flow-router-helpers